RafalWilinski / telegram-chatgpt-concierge-bot

Interact with OpenAI's ChatGPT via Telegram and Voice.
https://chatwithcloud.ai
1.13k stars 109 forks source link

Initailizes, but fails when posting request to openai. #2

Closed zachsa999 closed 1 year ago

zachsa999 commented 1 year ago

I changed the model to 3.5 to get around the waitlist, the bot initilizes, bu the server crashes when posting request to openai. here is the logs.


const { Input } = require("telegraf")

Healthcheck server listening on port undefined
Bot started
Input: Input
Entering new agent_executor chain...
(node: 20924) ExperimentalWarning: The Fetch API is an experimental feature.This feature could change at any time
    (Use`node --trace-warnings ...` to show where the warning was created)
Unhandled error while processing {
    update_id: 794716571,
        message: {
        message_id: 10,
            from: {
            id: 142483133,
                is_bot: false,
                    first_name: '',
                        last_name: '',
                            username: '',
                                language_code: 'en'
        },
        chat: {
            id: 142483133,
                first_name: '',
                    last_name: '',
                        username: 'username',
                            type: 'private'
        },
        date: 1681136303,
            text: 'text'
    }
}
/home/ / telegram - chatgpt - concierge - bot / node_modules / langchain / dist / util / axios - fetch - adapter.cjs: 313
return new axios_1.default.AxiosError(message, axios_1.default.AxiosError[code], config, request, response);
               ^
    AxiosError: Request failed with status code 404
    at createError(/home/ / telegram - chatgpt - concierge - bot / node_modules / langchain / dist / util / axios - fetch - adapter.cjs: 313: 16)
    at settle(/home/ / telegram - chatgpt - concierge - bot / node_modules / langchain / src / util / axios - fetch - adapter.js: 47: 3)
at / home /  / telegram - chatgpt - concierge - bot / node_modules / langchain / dist / util / axios - fetch - adapter.cjs: 181: 19
    at new Promise(<anonymous>)
    at fetchAdapter (/home//telegram-chatgpt-concierge-bot/node_modules/langchain/dist/util/axios-fetch-adapter.cjs:173:12)
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
        config: {
        transitional: {
        silentJSONParsing: true,
    forcedJSONParsing: true,
    clarifyTimeoutError: false
    },
    adapter: [AsyncFunction: fetchAdapter],
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    validateStatus: [Function: validateStatus],
    headers: {
        Accept: 'application/json, text/plain, */*',
    'Content-Type': 'application/json',
    'User-Agent': 'OpenAI/NodeJS/3.2.1',
    Authorization: 'Bearer sk-'
    },
    method: 'post',
    data: '{"model":"gpt-4","temperature":1,"top_p":1,"frequency_penalty":0,"presence_penalty":0,"max_tokens":4000,"n":1,"stop":["Observation:"],"stream":false,"messages":[{"role":"system","content":"Assistant is a large language model trained by OpenAI.\\n\\nAssistant is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, Assistant is able to generate human-like text based on the input it receives, allowing it to engage in natural-sounding conversations and provide responses that are coherent and relevant to the topic at hand.\\n\\nAssistant is constantly learning and improving, and its capabilities are constantly evolving. It is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics.\\n\\nOverall, Assistant is a powerful system that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether you need help with a specific question or just want to have a conversation about a particular topic, Assistant is here to assist."},{"role":"user","content":"TOOLS\\n------\\nAssistant can ask the user to use tools to look up information that may be helpful in answering the users original question. The tools the human can use are:\\n\\nGoogle Search Tool: This is Google. Use this tool to search the internet. Input should be a string\\n\\nRESPONSE FORMAT INSTRUCTIONS\\n----------------------------\\n\\nWhen responding to me please, please output a response in one of two formats:\\n\\n**Option 1:**\\nUse this if you want the human to use a tool.\\nMarkdown code snippet formatted in the following schema:\\n\\n```json\\n{\\n    \\"action\\": string \\\\ The action to take. Must be one of Google Search Tool\\n    \\"action_input\\": string \\\\ The input to the action\\n}\\n```\\n\\n**Option #2:**\\nUse this if you want to respond directly to the human. Markdown code snippet formatted in the following schema:\\n\\n```json\\n{\\n    \\"action\\": \\"Final Answer\\",\\n    \\"action_input\\": string \\\\ You should put what you want to return to use here\\n}\\n```\\n\\nUSER\'S INPUT\\n--------------------\\nHere is the user\'s input (remember to respond with a markdown code snippet of a json blob with a single action, and NOTHING else):\\n\\nLG Sunni"}]}',
    url: 'https://api.openai.com/v1/chat/completions'
  },
    request: Request {
        [Symbol(realm)]: {settingsObject: [Object] },
    [Symbol(state)]: {
        method: 'POST',
    localURLsOnly: false,
    unsafeRequest: false,
    body: [Object],
    client: [Object],
    reservedClient: null,
    replacesClientId: '',
    window: 'client',
    keepalive: false,
    serviceWorkers: 'all',
    initiator: '',
    destination: '',
    priority: null,
    origin: 'client',
    policyContainer: 'client',
    referrer: 'client',
    referrerPolicy: '',
    mode: 'cors',
    useCORSPreflightFlag: false,
    credentials: 'same-origin',
    useCredentials: false,
    cache: 'default',
    redirect: 'follow',
    integrity: '',
    cryptoGraphicsNonceMetadata: '',
    parserMetadata: '',
    reloadNavigation: false,
    historyNavigation: false,
    userActivation: false,
    taintedOrigin: false,
    redirectCount: 0,
    responseTainting: 'basic',
    preventNoCacheCacheControlHeaderModification: false,
    done: false,
    timingAllowFailed: false,
    headersList: [HeadersList],
    urlList: [Array],
    url: [URL]
    },
    [Symbol(signal)]: AbortSignal {
        [Symbol(kEvents)]: [SafeMap [Map]],
    [Symbol(events.maxEventTargetListeners)]: 10,
    [Symbol(events.maxEventTargetListenersWarned)]: false,
    [Symbol(kAborted)]: false,
    [Symbol(kReason)]: undefined,
    [Symbol(realm)]: [Object]
    },
    [Symbol(headers)]: Headers {
        [Symbol(headers list)]: [HeadersList],
    [Symbol(guard)]: 'request',
    [Symbol(realm)]: [Object]
    }
  },
    response: {
        ok: false,
    status: 404,
    statusText: 'Not Found',
    headers: Headers {
        [Symbol(headers list)]: [HeadersList],
    [Symbol(guard)]: 'none'
    },
    config: {
        transitional: [Object],
    adapter: [AsyncFunction: fetchAdapter],
    transformRequest: [Array],
    transformResponse: [Array],
    timeout: 0,
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    validateStatus: [Function: validateStatus],
    headers: [Object],
    method: 'post',
    data: '{"model":"gpt-4","temperature":1,"top_p":1,"frequency_penalty":0,"presence_penalty":0,"max_tokens":4000,"n":1,"stop":["Observation:"],"stream":false,"messages":[{"role":"system","content":"Assistant is a large language model trained by OpenAI.\\n\\nAssistant is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, Assistant is able to generate human-like text based on the input it receives, allowing it to engage in natural-sounding conversations and provide responses that are coherent and relevant to the topic at hand.\\n\\nAssistant is constantly learning and improving, and its capabilities are constantly evolving. It is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics.\\n\\nOverall, Assistant is a powerful system that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether you need help with a specific question or just want to have a conversation about a particular topic, Assistant is here to assist."},{"role":"user","content":"TOOLS\\n------\\nAssistant can ask the user to use tools to look up information that may be helpful in answering the users original question. The tools the human can use are:\\n\\nGoogle Search Tool: This is Google. Use this tool to search the internet. Input should be a string\\n\\nRESPONSE FORMAT INSTRUCTIONS\\n----------------------------\\n\\nWhen responding to me please, please output a response in one of two formats:\\n\\n**Option 1:**\\nUse this if you want the human to use a tool.\\nMarkdown code snippet formatted in the following schema:\\n\\n```json\\n{\\n    \\"action\\": string \\\\ The action to take. Must be one of Google Search Tool\\n    \\"action_input\\": string \\\\ The input to the action\\n}\\n```\\n\\n**Option #2:**\\nUse this if you want to respond directly to the human. Markdown code snippet formatted in the following schema:\\n\\n```json\\n{\\n    \\"action\\": \\"Final Answer\\",\\n    \\"action_input\\": string \\\\ You should put what you want to return to use here\\n}\\n```\\n\\nUSER\'S INPUT\\n--------------------\\nHere is the user\'s input (remember to respond with a markdown code snippet of a json blob with a single action, and NOTHING else):\\n\\nLG Sunni"}]}',
    url: 'https://api.openai.com/v1/chat/completions'
    },
    request: Request {
        [Symbol(realm)]: [Object],
    [Symbol(state)]: [Object],
    [Symbol(signal)]: [AbortSignal],
    [Symbol(headers)]: [Headers]
    },
    data: {error: [Object] }
  }
}```
kessl commented 1 year ago

Where did you change the model to GPT-3? I see "model":"gpt-4" in the request data.

I replaced gpt-4 with gpt-3.5-turbo and now get a 400 response code instead of 404 with the following error:

{
  error: {
    message: "This model's maximum context length is 4097 tokens. However, you requested 4476 tokens (476 in the messages, 4000 in the completion). Please reduce the length of the messages or completion.",
    type: 'invalid_request_error',
    param: 'messages',
    code: 'context_length_exceeded'
  }
}

It seems the prompt length needs to be reduced for GPT-3 somehow

RafalWilinski commented 1 year ago

You need access to GPT-4 or use model gpt-3.5-turbo. Now it's possible to configure via env variable OPENAI_MODEL

kessl commented 1 year ago

@RafalWilinski setting OPENAI_MODEL=gpt-3.5-turbo results in the error I posted above.

talebi1 commented 1 year ago

same issue here

zachsa999 commented 1 year ago

Where did you change the model to GPT-3? I see "model":"gpt-4" in the request data.

I replaced gpt-4 with gpt-3.5-turbo and now get a 400 response code instead of 404 with the following error:

{
  error: {
    message: "This model's maximum context length is 4097 tokens. However, you requested 4476 tokens (476 in the messages, 4000 in the completion). Please reduce the length of the messages or completion.",
    type: 'invalid_request_error',
    param: 'messages',
    code: 'context_length_exceeded'
  }
}

It seems the prompt length needs to be reduced for GPT-3 somehow

I fixed this by changing params.maxTokens in src/models/chatWithTools.ts to a smaller number, 300 works.

dougmorato commented 1 year ago

same as @zachsa999 , changing the .env to OPENAI_MODEL=gpt-3.5-turbo gives me a response code 400

Entering new agent_executor chain...
AxiosError: Request failed with status code 400
    at createError (/opt/telegram-chatgpt-concierge-bot/node_modules/langchain/dist/util/axios-fetch-adapter.cjs:313:16)
    at settle (/opt/telegram-chatgpt-concierge-bot/node_modules/langchain/src/util/axios-fetch-adapter.js:47:3)
    at /opt/telegram-chatgpt-concierge-bot/node_modules/langchain/dist/util/axios-fetch-adapter.cjs:181:19
    at new Promise (<anonymous>)
    at fetchAdapter (/opt/telegram-chatgpt-concierge-bot/node_modules/langchain/dist/util/axios-fetch-adapter.cjs:173:12)
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
..........
 method: 'post',
    data: '{"model":"gpt-3.5-turbo","temperature":1,"top_p":1,"frequency_penalty":0,"presence_penalty":0,"max_tokens":4000,"n":1,"stop":["Observation:"]