Update readme and env example fileCNSeniorious000/free-chat#21
![Logo of Sweep](/_next/image?url=%2Flogo.png&w=64&q=75)
Update readme and env example file
CNSeniorious000/free-chat#21
> >
Progress
.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' ifDEEPL_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
Run GitHub Actions for
.env.example
Modify
README.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 for
README.md
Plan
This is based on the results of the Planning step. The plan may expand from failed GitHub Actions runs.
.env.example
Run GitHub Actions for
.env.example
Modify
README.md
Run GitHub Actions for
README.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