<commit_before>package apiai

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
	"net/url"
)

type Context struct {
	Name     string            `json:"name"`
	Lifespan int               `json:"lifespan"`
	Params   map[string]string `json:"parameters"`
}

func (c *ApiClient) GetContexts(sessionId string) ([]Context, error) {
	req, err := http.NewRequest("GET", c.buildUrl("contexts", map[string]string{
		"sessionId": sessionId,
	}), nil)
	if err != nil {
		return nil, err
	}
	req.Header.Set("Accept", "application/json")
	req.Header.Set("Content-type", "application/json, charset=utf-8")
	req.Header.Set("Authorization", "Bearer "+c.config.Token)

	httpClient := http.DefaultClient
	resp, err := httpClient.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	var contexts []Context
	switch resp.StatusCode {
	case http.StatusOK:
		decoder := json.NewDecoder(resp.Body)
		err = decoder.Decode(&contexts)
		if err != nil {
			return nil, err
		}
		return contexts, nil
	default:
		return nil, fmt.Errorf("apiai: wops something happens because status code is %v", resp.StatusCode)
	}
}

func (c *ApiClient) GetContext(name, sessionId string) (*Context, error) {
	req, err := http.NewRequest("GET", c.buildUrl("contexts/"+url.QueryEscape(name), map[string]string{
		"sessionId": sessionId,
	}), nil)
	if err != nil {
		return nil, err
	}
	req.Header.Set("Accept", "application/json")
	req.Header.Set("Content-type", "application/json, charset=utf-8")
	req.Header.Set("Authorization", "Bearer "+c.config.Token)

	httpClient := http.DefaultClient
	resp, err := httpClient.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	var context *Context
	switch resp.StatusCode {
	case http.StatusOK:
		decoder := json.NewDecoder(resp.Body)
		err = decoder.Decode(&context)
		if err != nil {
			return nil, err
		}
		return context, nil
	default:
		return nil, fmt.Errorf("apiai: wops something happens because status code is %v", resp.StatusCode)
	}
}

func (c *ApiClient) CreateContext(context Context, sessionId string) error {
	body := new(bytes.Buffer)
	err := json.NewEncoder(body).Encode(context)
	if err != nil {
		return err
	}

	req, err := http.NewRequest("POST", c.buildUrl("contexts", map[string]string{
		"sessionId": sessionId,
	}), body)
	if err != nil {
		return err
	}
	req.Header.Set("Accept", "application/json")
	req.Header.Set("Content-type", "application/json, charset=utf-8")
	req.Header.Set("Authorization", "Bearer "+c.config.Token)

	httpClient := http.DefaultClient
	resp, err := httpClient.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	switch resp.StatusCode {
	case http.StatusOK:
		return nil
	default:
		return fmt.Errorf("apiai: wops something happens because status code is %v", resp.StatusCode)
	}
}

func (c *ApiClient) DeleteContexts(sessionId string) error {
	req, err := http.NewRequest("DELETE", c.buildUrl("contexts", map[string]string{
		"sessionId": sessionId,
	}), nil)
	if err != nil {
		return err
	}
	req.Header.Set("Accept", "application/json")
	req.Header.Set("Content-type", "application/json, charset=utf-8")
	req.Header.Set("Authorization", "Bearer "+c.config.Token)

	httpClient := http.DefaultClient
	resp, err := httpClient.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	switch resp.StatusCode {
	case http.StatusOK:
		return nil
	default:
		return fmt.Errorf("apiai: wops something happens because status code is %v", resp.StatusCode)
	}
}

func (c *ApiClient) DeleteContext(name, sessionId string) error {
	req, err := http.NewRequest("DELETE", c.buildUrl("contexts/"+url.QueryEscape(name), map[string]string{
		"sessionId": sessionId,
	}), nil)
	if err != nil {
		return err
	}
	req.Header.Set("Accept", "application/json")
	req.Header.Set("Content-type", "application/json, charset=utf-8")
	req.Header.Set("Authorization", "Bearer "+c.config.Token)

	httpClient := http.DefaultClient
	resp, err := httpClient.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	switch resp.StatusCode {
	case http.StatusOK:
		return nil
	default:
		return fmt.Errorf("apiai: wops something happens because status code is %v", resp.StatusCode)
	}
}
<commit_msg>fix CreateContext header<commit_after>package apiai

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
	"net/url"
)

type Context struct {
	Name     string            `json:"name"`
	Lifespan int               `json:"lifespan"`
	Params   map[string]string `json:"parameters"`
}

func (c *ApiClient) GetContexts(sessionId string) ([]Context, error) {
	req, err := http.NewRequest("GET", c.buildUrl("contexts", map[string]string{
		"sessionId": sessionId,
	}), nil)
	if err != nil {
		return nil, err
	}
	req.Header.Set("Accept", "application/json")
	req.Header.Set("Content-type", "application/json; charset=utf-8")
	req.Header.Set("Authorization", "Bearer "+c.config.Token)

	httpClient := http.DefaultClient
	resp, err := httpClient.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	var contexts []Context
	switch resp.StatusCode {
	case http.StatusOK:
		decoder := json.NewDecoder(resp.Body)
		err = decoder.Decode(&contexts)
		if err != nil {
			return nil, err
		}
		return contexts, nil
	default:
		return nil, fmt.Errorf("apiai: wops something happens because status code is %v", resp.StatusCode)
	}
}

func (c *ApiClient) GetContext(name, sessionId string) (*Context, error) {
	req, err := http.NewRequest("GET", c.buildUrl("contexts/"+url.QueryEscape(name), map[string]string{
		"sessionId": sessionId,
	}), nil)
	if err != nil {
		return nil, err
	}
	req.Header.Set("Accept", "application/json")
	req.Header.Set("Content-type", "application/json; charset=utf-8")
	req.Header.Set("Authorization", "Bearer "+c.config.Token)

	httpClient := http.DefaultClient
	resp, err := httpClient.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	var context *Context
	switch resp.StatusCode {
	case http.StatusOK:
		decoder := json.NewDecoder(resp.Body)
		err = decoder.Decode(&context)
		if err != nil {
			return nil, err
		}
		return context, nil
	default:
		return nil, fmt.Errorf("apiai: wops something happens because status code is %v", resp.StatusCode)
	}
}

func (c *ApiClient) CreateContext(context Context, sessionId string) error {
	body := new(bytes.Buffer)
	err := json.NewEncoder(body).Encode(context)
	if err != nil {
		return err
	}

	req, err := http.NewRequest("POST", c.buildUrl("contexts", map[string]string{
		"sessionId": sessionId,
	}), body)
	if err != nil {
		return err
	}
	req.Header.Set("Accept", "application/json")
	req.Header.Set("Content-type", "application/json; charset=utf-8")
	req.Header.Set("Authorization", "Bearer "+c.config.Token)

	httpClient := http.DefaultClient
	resp, err := httpClient.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	switch resp.StatusCode {
	case http.StatusOK:
		return nil
	default:
		return fmt.Errorf("apiai: wops something happens because status code is %v", resp.StatusCode)
	}
}

func (c *ApiClient) DeleteContexts(sessionId string) error {
	req, err := http.NewRequest("DELETE", c.buildUrl("contexts", map[string]string{
		"sessionId": sessionId,
	}), nil)
	if err != nil {
		return err
	}
	req.Header.Set("Accept", "application/json")
	req.Header.Set("Content-type", "application/json; charset=utf-8")
	req.Header.Set("Authorization", "Bearer "+c.config.Token)

	httpClient := http.DefaultClient
	resp, err := httpClient.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	switch resp.StatusCode {
	case http.StatusOK:
		return nil
	default:
		return fmt.Errorf("apiai: wops something happens because status code is %v", resp.StatusCode)
	}
}

func (c *ApiClient) DeleteContext(name, sessionId string) error {
	req, err := http.NewRequest("DELETE", c.buildUrl("contexts/"+url.QueryEscape(name), map[string]string{
		"sessionId": sessionId,
	}), nil)
	if err != nil {
		return err
	}
	req.Header.Set("Accept", "application/json")
	req.Header.Set("Content-type", "application/json; charset=utf-8")
	req.Header.Set("Authorization", "Bearer "+c.config.Token)

	httpClient := http.DefaultClient
	resp, err := httpClient.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	switch resp.StatusCode {
	case http.StatusOK:
		return nil
	default:
		return fmt.Errorf("apiai: wops something happens because status code is %v", resp.StatusCode)
	}
}

{'fraction_non_alphanumeric': 0.15093441256993215, 'fraction_numerical': 0.0011903344839900012, 'mean_word_length': 4.334603174603175, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2788633', 'n_tokens_mistral': 2992, 'n_tokens_neox': 2891, 'n_words': 710}