( controller: ReadableStreamDefaultController, conversationId: number, actions: ActionPlusApiInfo[], reqData: AnswersType, org: OrgJoinIsPaidFinetunedModels, language: string | null, )
| 700 | } |
| 701 | |
| 702 | async function preamble( |
| 703 | controller: ReadableStreamDefaultController, |
| 704 | conversationId: number, |
| 705 | actions: ActionPlusApiInfo[], |
| 706 | reqData: AnswersType, |
| 707 | org: OrgJoinIsPaidFinetunedModels, |
| 708 | language: string | null, |
| 709 | ) { |
| 710 | const encoder = new TextEncoder(); |
| 711 | |
| 712 | function streamInfo(step: StreamingStepInput) { |
| 713 | controller.enqueue( |
| 714 | encoder.encode( |
| 715 | "data: " + |
| 716 | JSON.stringify({ |
| 717 | id: conversationId, |
| 718 | ...step, |
| 719 | }), |
| 720 | ), |
| 721 | ); |
| 722 | } |
| 723 | |
| 724 | if (redis) { |
| 725 | // Store the system prompt, in case we get feedback on it |
| 726 | const redisKey = conversationId.toString() + "-system-prompt"; |
| 727 | const systemPrompt = |
| 728 | actions.length > 0 |
| 729 | ? getMessages( |
| 730 | [], |
| 731 | actions, |
| 732 | reqData.user_description, |
| 733 | org, |
| 734 | language, |
| 735 | // TODO: ID line isn't always included, but we don't know whether it should be at this point (no functions called yet) |
| 736 | false, |
| 737 | )[0].content |
| 738 | : chatToDocsPrompt(reqData.user_description, org, false, language) |
| 739 | .content; |
| 740 | await redis.set(redisKey, systemPrompt); |
| 741 | await redis.expire(redisKey, 60 * 15); |
| 742 | } |
| 743 | return streamInfo; |
| 744 | } |
| 745 | |
| 746 | export async function storeActionsAwaitingConfirmation( |
| 747 | toConfirm: ToConfirm[], |
no test coverage detected