MCPcopy Index your code
hub / github.com/Xyntopia/taskyon / processChatTask

Function processChatTask

src/modules/taskWorker.ts:64–154  ·  view source on GitHub ↗
(
  task: LLMTask,
  chatState: ChatStateType,
  db: TaskyonDatabase
)

Source from the content-addressed store, hash-verified

62}
63
64export async function processChatTask(
65 task: LLMTask,
66 chatState: ChatStateType,
67 db: TaskyonDatabase
68) {
69 //TODO: merge this function with the assistants function
70 if (chatState.useOpenAIAssistants && openAIUsed(chatState.baseURL)) {
71 const messages = await getOpenAIAssistantResponse(task, chatState, db);
72 if (messages) {
73 task.result = {
74 type: 'AssistantAnswer',
75 assistantResponse: messages,
76 };
77 }
78 } else {
79 console.log('execute chat task!', task);
80 //TODO: also do this, if we start the task "autonomously" in which we basically
81 // allow it to create new tasks...
82 //TODO: we can create more things here like giving it context form other tasks, lookup
83 // main objective, previous tasks etc....
84 const useToolChat =
85 task.allowedTools?.length && !chatState.enableOpenAiTools;
86
87 const { openAIConversationThread, tools } = prepareTasksForInference(
88 task,
89 chatState,
90 useToolChat ? 'toolchat' : 'chat'
91 );
92
93 if (openAIConversationThread.length > 0) {
94 const chatCompletion = await callLLM(
95 openAIConversationThread,
96 tools,
97 chatState,
98 getSelectedModel(chatState),
99 getAPIURLs(chatState.baseURL).chat,
100 // if the task runs in the "foreground", stream it :)
101 task.id == chatState.selectedTaskId ? true : false,
102 // this function receives chunks if we stream and "plants" them into
103 // our original task
104 (chunk) => {
105 if (chunk?.choices[0]?.delta?.tool_calls) {
106 chunk?.choices[0]?.delta?.tool_calls.forEach((t) => {
107 task.debugging.toolStreamArgsContent =
108 task.debugging.toolStreamArgsContent || {};
109 if (t.function?.name) {
110 task.debugging.toolStreamArgsContent[t.function.name] =
111 (task.debugging.toolStreamArgsContent[t.function.name] ||
112 '') + (t.function?.arguments || '');
113 }
114 });
115 }
116 if (chunk?.choices[0]?.delta?.content) {
117 task.debugging.streamContent =
118 (task.debugging.streamContent || '') +
119 chunk.choices[0].delta.content;
120 }
121 }

Callers 1

taskWorkerFunction · 0.85

Calls 10

openAIUsedFunction · 0.90
prepareTasksForInferenceFunction · 0.90
callLLMFunction · 0.90
getSelectedModelFunction · 0.90
getAPIURLsFunction · 0.90
openRouterUsedFunction · 0.90
estimateChatTokensFunction · 0.90
isOpenAIFunctionCallFunction · 0.85

Tested by

no test coverage detected