MCPcopy Create free account
hub / github.com/Superflows-AI/superflows / textFromResponse

Function textFromResponse

lib/queryLLM.ts:86–108  ·  view source on GitHub ↗
(
  response:
    | ChatGPTResponse
    | RunPodResponse
    | TogetherAIResponse
    | AnthropicLegacyResponse
    | Claude3Response,
)

Source from the content-addressed store, hash-verified

84}
85
86export 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
110export async function streamLLMResponse(
111 prompt: ChatGPTMessage[] | string,

Callers 1

getLLMResponseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected