File tree Expand file tree Collapse file tree 4 files changed +54
-3
lines changed
Expand file tree Collapse file tree 4 files changed +54
-3
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ This is the lightweight analogue of @cocalc/server/llm
3+ */
4+
5+ import {
6+ evaluateWithLangChain ,
7+ evaluateOllama ,
8+ heuristicNumTokens ,
9+ } from "@cocalc/ai/llm" ;
10+ import { init as initConatLLM } from "@cocalc/conat/llm/server" ;
11+ import { isOllamaLLM } from "@cocalc/util/db-schema/llm-utils" ;
12+ import { listRows } from "./sqlite/database" ;
13+
14+ function buildContext ( ) {
15+ const settings : Record < string , any > = { } ;
16+ for ( const row of listRows ( "server_settings" ) as {
17+ name ?: string ;
18+ value ?: any ;
19+ } [ ] ) {
20+ if ( row . name ) {
21+ settings [ row . name ] = row . value ;
22+ }
23+ }
24+
25+ return {
26+ settings : {
27+ openai_api_key : settings . openai_api_key ,
28+ google_vertexai_key : settings . google_vertexai_key ,
29+ anthropic_api_key : settings . anthropic_api_key ,
30+ mistral_api_key : settings . mistral_api_key ,
31+ } ,
32+ mode : "user" as const ,
33+ tokenCounter : heuristicNumTokens ,
34+ } ;
35+ }
36+
37+ export async function init ( ) : Promise < void > {
38+ await initConatLLM ( async ( opts : any ) => {
39+ const context = buildContext ( ) ;
40+ if ( isOllamaLLM ( opts . model ) ) {
41+ return evaluateOllama ( opts ) ;
42+ }
43+ return evaluateWithLangChain ( opts , context ) ;
44+ } ) ;
45+ }
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ import { localPathFileserver } from "@cocalc/backend/conat/files/local-path";
2828import { init as initBugCounter } from "@cocalc/project/bug-counter" ;
2929import { init as initChangefeeds } from "./hub/changefeeds" ;
3030import { init as initHubApi } from "./hub/api" ;
31+ import { init as initLLM } from "./hub/llm" ;
3132import { account_id } from "@cocalc/backend/data" ;
3233import { init as initRemote } from "./remote" ;
3334import { getAuthToken } from "./auth-token" ;
@@ -96,6 +97,9 @@ export async function main(): Promise<number> {
9697 logger . debug ( "start changefeed server" ) ;
9798 initChangefeeds ( { client : conatClient } ) ;
9899
100+ logger . debug ( "start llm conat server" ) ;
101+ await initLLM ( ) ;
102+
99103 const path = process . cwd ( ) ;
100104
101105 logger . debug ( "start hub api" ) ;
Original file line number Diff line number Diff line change 3232 "dependencies" : {
3333 "@cocalc/assets" : " workspace:*" ,
3434 "@cocalc/backend" : " workspace:*" ,
35+ "@cocalc/ai" : " workspace:*" ,
3536 "@cocalc/conat" : " workspace:*" ,
3637 "@cocalc/lite" : " workspace:*" ,
3738 "@cocalc/project" : " workspace:*" ,
You can’t perform that action at this time.
0 commit comments