Skip to content

Commit

Permalink
feat: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgutgon committed Jan 15, 2025
1 parent 915f766 commit 5f622ed
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export default function Chat({
}
break
}

default:
break
}
Expand Down Expand Up @@ -221,6 +222,8 @@ export default function Chat({

switch (event) {
case StreamEventTypes.Latitude: {
console.log('DATA', data)

if (data.type === ChainEventTypes.Complete) {
setUsage(data.response.usage)
} else if (data.type === ChainEventTypes.Error) {
Expand All @@ -237,6 +240,7 @@ export default function Chat({
}
break
}

default:
break
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ const toolResultContentSchema = z.object({
type: z.literal('tool-result'),
toolCallId: z.string(),
toolName: z.string(),
result: z.string(),
result: z.any(),
isError: z.boolean().optional(),
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Config } from '../../ai'
import { ChainError } from '../ChainErrors'
import { ValidatedStep } from '../ChainValidator'
import { FinishReason } from 'ai'
import { buildMessagesFromResponse } from '../../../helpers'

export function enqueueChainEvent(
controller: ReadableStreamDefaultController,
Expand Down Expand Up @@ -141,13 +142,15 @@ export class ChainStreamConsumer {
step,
response,
finishReason,
responseMessages,
responseMessages: defaultResponseMessages,
}: {
step: ValidatedStep
response: ChainStepResponse<StreamType>
finishReason: FinishReason
responseMessages: Message[]
responseMessages?: Message[]
}) {
const responseMessages =
defaultResponseMessages ?? buildMessagesFromResponse({ response })
return ChainStreamConsumer.chainCompleted({
controller: this.controller,
response,
Expand Down
9 changes: 3 additions & 6 deletions packages/core/src/services/chains/buildStep/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from '../ProviderProcessor/saveOrPublishProviderLogs'
import { cacheChain } from '../chainCache'
import { buildMessagesFromResponse } from '../../../helpers'
import { Message } from '@latitude-data/compiler'

function getToolCalls({
response,
Expand Down Expand Up @@ -72,11 +71,9 @@ export async function buildStepExecution({
const isPromptl = chain instanceof PromptlChain
const toolCalls = getToolCalls({ response: finalResponse })
const hasTools = isPromptl && toolCalls.length > 0
let responseMessages: Message[] = []

if (hasTools || step.chainCompleted) {
responseMessages = buildMessagesFromResponse({ response: finalResponse })
}
const responseMessages = buildMessagesFromResponse({
response: finalResponse,
})

if (hasTools) {
await cacheChain({
Expand Down
6 changes: 2 additions & 4 deletions packages/core/src/services/chains/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ export async function runStep({
streamConsumer.chainCompleted({
step,
response: previousResponse!,
finishReason: 'stop',
responseMessages: [],
finishReason: previousResponse?.finishReason ?? 'stop',
})

previousResponse!.chainCompleted = true
return previousResponse!
}

Expand Down Expand Up @@ -242,7 +242,6 @@ export async function runStep({
return executeStep({ finalResponse })
}

messages.forEach((m) => console.log('Message TO AI:', m))
const aiResult = await ai({
messages,
config: step.config,
Expand All @@ -261,7 +260,6 @@ export async function runStep({

if (consumedStream.error) throw consumedStream.error

step.chainCompleted
const _response = await processResponse({
aiResult,
apiProvider: step.provider,
Expand Down
4 changes: 1 addition & 3 deletions packages/web-ui/src/ds/molecules/Chat/Message/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ function JSONContent({ content }: { content: unknown }) {
return (
<div className='py-2 max-w-full'>
<div className='overflow-hidden rounded-xl w-full'>
<CodeBlock language='json'>
{JSON.stringify(parsedValue, null, 2)}
</CodeBlock>
<CodeBlock language='json'>{parsedValue}</CodeBlock>
</div>
</div>
)
Expand Down

0 comments on commit 5f622ed

Please sign in to comment.