Skip to content

Commit

Permalink
handle no text in message
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-dixon committed Oct 25, 2024
1 parent af9609e commit d7a643e
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions typescript/src/lmp/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as sourceMapSupport from 'source-map-support'
import { Kwargs } from "./types"
import { config } from "../configurator"
import { APICallResult } from "../provider"
import { Message } from "../types/message"
import { Kwargs } from './types'
import { config } from '../configurator'
import { Message } from '../types/message'
import { callsites } from '../util/callsites'
import * as logging from '../util/_logging'

const logger = logging.getLogger('ell')

export const getModelClient = async (args: Kwargs) => {
if (args.client) {
Expand All @@ -13,17 +15,31 @@ export const getModelClient = async (args: Kwargs) => {
return client
}


export const convertMultimodalResponseToLstr = (response: Message[]) => {
if (response.length === 1 && response[0].content.length === 1 && response[0].content[0].text) {
return response[0].content[0].text
}
return response
}
export function convertMultimodalResponseToString(response: APICallResult['response']): string | string[] {
return Array.isArray(response) ? response.map((x) => x.content[0].text) : response.content[0].text
}

export function convertMultimodalResponseToString(response: Message | Message[]): string | string[] {
if (Array.isArray(response)) {
return response.map((x) => {
const text = x.content[0].text
if (text) {
return text
}
logger.warn(`No text found in message: ${JSON.stringify(x)}`)
return ''
})
}
const text = response.content[0].text
if (text) {
return text
}
logger.warn(`No text found in message: ${JSON.stringify(response)}`)
return ''
}

export function getCallerFileLocation() {
const callerSite = callsites()[2]
Expand All @@ -41,4 +57,4 @@ export function getCallerFileLocation() {
column = mappedPosition.column
}
return { filepath: file, line, column }
}
}

0 comments on commit d7a643e

Please sign in to comment.