| const axios = require('axios'); |
| const { logAxiosError } = require('@librechat/api'); |
| const { EModelEndpoint } = require('librechat-data-provider'); |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| async function retrieveRun({ thread_id, run_id, timeout, openai }) { |
| const appConfig = openai.req.config; |
| const { apiKey, baseURL, httpAgent, organization } = openai; |
| let url = `${baseURL}/threads/${thread_id}/runs/${run_id}`; |
|
|
| let headers = { |
| Authorization: `Bearer ${apiKey}`, |
| 'OpenAI-Beta': 'assistants=v1', |
| }; |
|
|
| if (organization) { |
| headers['OpenAI-Organization'] = organization; |
| } |
|
|
| |
| const azureConfig = appConfig.endpoints?.[EModelEndpoint.azureOpenAI]; |
|
|
| if (azureConfig && azureConfig.assistants) { |
| delete headers.Authorization; |
| headers = { ...headers, ...openai._options.defaultHeaders }; |
| const queryParams = new URLSearchParams(openai._options.defaultQuery).toString(); |
| url = `${url}?${queryParams}`; |
| } |
|
|
| try { |
| const axiosConfig = { |
| headers: headers, |
| timeout: timeout, |
| }; |
|
|
| if (httpAgent) { |
| axiosConfig.httpAgent = httpAgent; |
| axiosConfig.httpsAgent = httpAgent; |
| } |
|
|
| const response = await axios.get(url, axiosConfig); |
| return response.data; |
| } catch (error) { |
| const message = '[retrieveRun] Failed to retrieve run data:'; |
| throw new Error(logAxiosError({ message, error })); |
| } |
| } |
|
|
| module.exports = { retrieveRun }; |
|
|