| 84 | } |
| 85 | |
| 86 | export function textFromResponse( |
| 87 | response: |
| 88 | | ChatGPTResponse |
| 89 | | RunPodResponse |
| 90 | | TogetherAIResponse |
| 91 | | AnthropicLegacyResponse |
| 92 | | Claude3Response, |
| 93 | ): string { |
| 94 | if ("completion" in response) return response.completion; |
| 95 | if ("content" in response) { |
| 96 | // Claude 3 |
| 97 | return response.content[0].text; |
| 98 | } |
| 99 | if ("output" in response) { |
| 100 | if (typeof response.output === "string") return response.output; |
| 101 | // @ts-ignore |
| 102 | return response.output.choices[0].text; |
| 103 | } |
| 104 | /* Assumes that you have set n = 1 in the params */ |
| 105 | if ("message" in response.choices[0]) |
| 106 | return response.choices[0].message.content; |
| 107 | return response.choices[0].text; |
| 108 | } |
| 109 | |
| 110 | export async function streamLLMResponse( |
| 111 | prompt: ChatGPTMessage[] | string, |