Logo of Sweep
Update readme and env example fileCNSeniorious000/free-chat#21

> >

  Started 8 months ago (probably frozen) using GPT-4  •   Book a call  •   Report a bug


Progress

  Modify.env.example 
1# Your API Key for OpenAI
2OPENAI_API_KEY=
3# Default temperature for OpenAI API
4OPENAI_API_TEMPERATURE=
5# Provide proxy for OpenAI API.
6HTTPS_PROXY=
7# Custom base url for OpenAI API. default: https://api.openai.com
8OPENAI_API_BASE_URL=
9# Inject analytics or other scripts before </head> of the page
10HEAD_SCRIPTS=
11# Secret string for the project. Use for generating signatures for API calls
12SECRET_KEY=
13# Set password for site. If not set, site will be public
14SITE_PASSWORD=
15# ID of the model to use. https://platform.openai.com/docs/api-reference/chat/create#chat/create-model
16OPENAI_API_MODEL=
17# url of the tutorial markdown file
18TUTORIAL_MD_URL=
19# url of the advertisement iframe
20PUBLIC_IFRAME_URL=
21# user-agent for backend requests
22UNDICI_UA=
23# whether your messages should be right-aligned
24PUBLIC_RIGHT_ALIGN_MY_MSG=
  • Add the following environment variables to the .env.example file:
    • OPENAI_API_BASE_URL: The base URL for the OpenAI API. Default is 'https://api.openai.com'.
    • TRANSCRIPT_TARGET_LANG: The target language for the transcript. Default is 'zh'.
    • TRANSCRIPT_PROMPT: The prompt for the transcript. Default is '你好。\n\n你好。\n\n你好。\n\n'.
    • DEEPL_AUTH_TOKEN: The authentication token for DeepL.
    • TRANSLATE_PROVIDER: The provider for translation. If not 'cf', DeepL is used.
    • TRANSLATE_TARGET_LANG: The target language for translation. Default is 'ZH' for DeepL and 'chinese' for others.
    • DEEPL_API_HOST: The API host for DeepL. Default is 'api-free.deepl.com' if DEEPL_AUTH_TOKEN ends with ':fx', otherwise 'api.deepl.com'.
    • CF_ACCOUNT_ID: The account ID for Cloudflare.
    • CF_API_TOKEN: The API token for Cloudflare.

Modifying file with Assistant API

Instructions (1)
You're a brilliant engineer assigned to make an edit to solve a GitHub issue. Modify the attached file to complete the task by writing Python code to read and make edits to the file. Be careful of syntax errors, such as multiline variables, indentation, and string formatting. You must complete all three steps before returning your response.

# Guide
## Step 1: Setup Helper Functions and Identify Relevant Lines
First instantiate and run all of the following code. Then identify the relevant lines by running `print_original_lines` and `print_original_lines_with_keywords`:

### HELPER FUNCTIONS TO RUN
```python
# First read and load the helper functions into the current context. This will allow you to use the helper functions in the rest of the code.
helper_methods_path = '/mnt/data/file-delGVODvbP7irMg5R9Hp46b9'
with open(helper_methods_path, 'r') as f:
    helper_methods = f.read()
print(helper_methods)
exec(helper_methods)
```

Use the helper functions to identify the minimum set of lines of code you must modify.

## Step 2: Iterative Code Modification
You will iteratively make small edits. Before making each edit, make a backup of the current_content by running:

```python
prev_content = current_content
```

### Modification script
For each section to change, run one of the following:

```python
# Remember to escape quotations
old_content = "Old content"
new_content = "New content"
assert old_content in current_content # if this fails then identify a new section to change
current_content = current_content.replace(old_content, new_content, 1) # avoid other accidental changes
```

### Validation
Then review the changes of the current edit by running:

```python
# Double check the change
print_diff(current_content, prev_content)
```

### Revert (optional)
If the change is invalid or looks incorrect, revert it by running the below snippet and trying again:

```python
current_content = prev_content
# then try making the change again, optionally using set_indentation(code, num_indents=4) to fix indentation
```

Move to Step 3 once all the edits are completed.

## Step 3: Final Review and Response
Perform a final review once all edits from Step 2 are completed. Use the following code:

```python
print(current_content)
print_diff(current_content, final_diff=True)
```

Finally, print the final valid diff using the print_diff function.
Assistant (2)
I will make the necessary changes to the `.env.example` file and the `README*` files to update the relevant information related to the `import.meta.env` usage. I will run the helper function to load the file content and identify the relevant lines.
  Run GitHub Actions for.env.example 
  ModifyREADME.md 
1<h1 align="center">Free Chat</h1>
2
3<div align="center">English | <a href="./README.zh-CN.md">简体中文</a></div>
4
5<br>
6
7> Forked from [chatgpt-demo](https://github.com/anse-app/chatgpt-demo). Find deployment instructions in the original repository.
8
9## Environment Variables
10
11You can control the website through environment variables.
12
13| Name | Description | Default |
14| --- | --- | --- |
15| `OPENAI_API_KEY` | Your API Key for OpenAI. | `null` |
16| `OPENAI_API_TEMPERATURE` | Default `temperature` parameter for model. | `1.0` |
17| `HTTPS_PROXY` | Provide proxy for OpenAI API. | `null` |
18| `OPENAI_API_BASE_URL` | Custom base url for OpenAI API. | `https://api.openai.com` |
19| `HEAD_SCRIPTS` | Inject analytics or other scripts before `</head>` of the page | `null` |
20| `PUBLIC_SECRET_KEY` | Secret string for the project. Use for generating signatures for API calls | `null` |
21| `SITE_PASSWORD` | Set password for site. If not set, site will be public | `null` |
22| `OPENAI_API_MODEL` | ID of the model to use. [Model endpoint compatibility](https://platform.openai.com/docs/models/model-endpoint-compatibility) | `gpt-3.5-turbo-1106` |
23| `TUTORIAL_MD_URL` | url of the tutorial markdown file | `null` |
24| `PUBLIC_IFRAME_URL` | url of the advertisement iframe | `null` |
25| `UNDICI_UA` | user-agent for backend requests | `(forward)` |
26| `PUBLIC_RIGHT_ALIGN_MY_MSG` | whether user messages should be right-aligned | `null` |
27| `PUBLIC_CL100K_BASE_JSON_URL` | CDN url for `cl100k_base.json`, such as [file at jsdelivr.net](https://cdn.jsdelivr.net/npm/tiktoken@1.0.10/encoders/cl100k_base.json) | `null` |
28| `PUBLIC_TIKTOKEN_BG_WASM_URL` | CDN url for `tiktoken_bg.wasm`, such as [file at esm.sh](https://esm.sh/tiktoken/lite/tiktoken_bg.wasm) | `null` |
29
30## Contributing
31
32This project exists thanks to all those who contributed to [the original project](https://github.com/anse-app/chatgpt-demo).
33
34Thank you to all our supporters!🙏
35
36[![img](https://contributors.nn.ci/api?repo=anse-app/chatgpt-demo)](https://github.com/ddiu8081/chatgpt-demo/graphs/contributors)
37
38## License
39
40MIT © [Muspi Merol](./LICENSE)
41
  • Update the environment variables section in the README.md file to include the above-mentioned environment variables along with their descriptions and default values.
  Run GitHub Actions forREADME.md 

Plan

This is based on the results of the Planning step. The plan may expand from failed GitHub Actions runs.

  Modify.env.example 
  Run GitHub Actions for.env.example 
  ModifyREADME.md 
  Run GitHub Actions forREADME.md 

Code Snippets Found

This is based on the results of the Searching step.

src/pages/api/transcript.ts:0-935 
1import { getHeaders } from '@/utils/header'
2import type { APIRoute } from 'astro'
3const baseUrl = ((import.meta.env.OPENAI_API_BASE_URL) || 'https://api.openai.com').trim().replace(/\/$/, '')
4
5export const post: APIRoute = async(context) => {
6  const headers = getHeaders(context.request)
7
8  const prompt = '你好。\n\n你好。\n\n你好。\n\n'
9
10  const formData = new FormData()
11  formData.append('model', 'whisper-1')
12  formData.append('language', import.meta.env.TRANSCRIPT_TARGET_LANG ?? 'zh')
13  formData.append('response_format', 'text')
14  formData.append('prompt', import.meta.env.TRANSCRIPT_PROMPT ?? prompt)
15  formData.append('file', await context.request.blob(), 'file.webm')
16
17  const text = await fetch(`${baseUrl}/v1/audio/transcriptions`, { method: 'POST', headers, body: formData }).then(res => res.text())
18
19  console.error({ text })
20
21  return new Response(text.trim(), { headers: { 'Content-Type': 'text/plain' } })
22}
23
src/pages/api/translate.ts:0-1153 
1import { run } from '../../utils/cf-workers-ai'
2import type { APIRoute } from 'astro'
3
4const deeplAuthKey = import.meta.env.DEEPL_AUTH_TOKEN
5const useDeepL = deeplAuthKey && import.meta.env.TRANSLATE_PROVIDER !== 'cf'
6const target_lang = import.meta.env.TRANSLATE_TARGET_LANG ?? (useDeepL ? 'ZH' : 'chinese')
7
8export const get: APIRoute = async(context) => {
9  const text = context.url.searchParams.get('text')
10  if (useDeepL) {
11    const host = import.meta.env.DEEPL_API_HOST ?? (deeplAuthKey.endsWith(':fx') ? 'api-free.deepl.com' : 'api.deepl.com')
12    const headers = { 'Authorization': `DeepL-Auth-Key ${deeplAuthKey}`, 'Content-Type': 'application/json' }
13    const { translations: [{ text: translated_text, detected_source_language }] } = await fetch(`https://${host}/v2/translate`, { method: 'POST', headers, body: JSON.stringify({ text: [text], target_lang }) }).then(res => res.json())
14    return new Response(translated_text, { headers: { 'x-detected-source-language': detected_source_language } })
15  }
16  const { result: { translated_text } } = await run('@cf/meta/m2m100-1.2b', { text, target_lang })
17  return new Response(translated_text)
18}
19
src/utils/cf-workers-ai.ts:0-493 
1export async function run(model: string, input: any) {
2  if (!import.meta.env.CF_ACCOUNT_ID || !import.meta.env.CF_API_TOKEN) throw new Error('cloudflare configuration not found')
3
4  const res = await fetch(
5      `https://api.cloudflare.com/client/v4/accounts/${import.meta.env.CF_ACCOUNT_ID}/ai/run/${model}`,
6      {
7        headers: { Authorization: `Bearer ${import.meta.env.CF_API_TOKEN}` },
8        method: 'POST',
9        body: JSON.stringify(input),
10      },
11  )
12  return res.json()
13}
14
README.md:15-30 
15| `OPENAI_API_KEY` | Your API Key for OpenAI. | `null` |
16| `OPENAI_API_TEMPERATURE` | Default `temperature` parameter for model. | `1.0` |
17| `HTTPS_PROXY` | Provide proxy for OpenAI API. | `null` |
18| `OPENAI_API_BASE_URL` | Custom base url for OpenAI API. | `https://api.openai.com` |
19| `HEAD_SCRIPTS` | Inject analytics or other scripts before `</head>` of the page | `null` |
20| `PUBLIC_SECRET_KEY` | Secret string for the project. Use for generating signatures for API calls | `null` |
21| `SITE_PASSWORD` | Set password for site. If not set, site will be public | `null` |
22| `OPENAI_API_MODEL` | ID of the model to use. [Model endpoint compatibility](https://platform.openai.com/docs/models/model-endpoint-compatibility) | `gpt-3.5-turbo-1106` |
23| `TUTORIAL_MD_URL` | url of the tutorial markdown file | `null` |
24| `PUBLIC_IFRAME_URL` | url of the advertisement iframe | `null` |
25| `UNDICI_UA` | user-agent for backend requests | `(forward)` |
26| `PUBLIC_RIGHT_ALIGN_MY_MSG` | whether user messages should be right-aligned | `null` |
27| `PUBLIC_CL100K_BASE_JSON_URL` | CDN url for `cl100k_base.json`, such as [file at jsdelivr.net](https://cdn.jsdelivr.net/npm/tiktoken@1.0.10/encoders/cl100k_base.json) | `null` |
28| `PUBLIC_TIKTOKEN_BG_WASM_URL` | CDN url for `tiktoken_bg.wasm`, such as [file at esm.sh](https://esm.sh/tiktoken/lite/tiktoken_bg.wasm) | `null` |
29
30## Contributing