-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
99 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { db as database } from '../db' | ||
import { embeddings as embeddingsTable } from '../db/schema/embeddings' | ||
import { | ||
insertResourceSchema, | ||
type NewResourceParameters, | ||
resources, | ||
} from '../db/schema/resources' | ||
import { generateEmbeddings } from './embeddings' | ||
|
||
export const createResource = async ( | ||
input: NewResourceParameters, | ||
): Promise<string> => { | ||
try { | ||
const { content } = insertResourceSchema.parse(input) | ||
|
||
const [resource] = await database | ||
.insert(resources) | ||
.values({ content }) | ||
.returning() | ||
|
||
if (!resource) { | ||
return 'Resource not found' | ||
} | ||
|
||
const embeddings = await generateEmbeddings(content) | ||
await database.insert(embeddingsTable).values( | ||
embeddings.map((embedding) => ({ | ||
resourceId: resource.id, | ||
...embedding, | ||
})), | ||
) | ||
|
||
return 'Resource successfully created and embedded.' | ||
} catch (error) { | ||
return error instanceof Error && error.message.length > 0 | ||
? error.message | ||
: 'Error, please try again.' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { openai as originalOpenAI } from '@ai-sdk/openai' | ||
import { | ||
experimental_createProviderRegistry as createProviderRegistry, | ||
experimental_customProvider as customProvider, | ||
} from 'ai' | ||
import { ollama as originalOllama } from 'ollama-ai-provider' | ||
|
||
const ollama = customProvider({ | ||
fallbackProvider: originalOllama, | ||
languageModels: { | ||
'qwen-2_5': originalOllama('qwen2.5'), | ||
}, | ||
}) | ||
|
||
export const openai = customProvider({ | ||
fallbackProvider: originalOpenAI, | ||
languageModels: { | ||
'gpt-4o-mini': originalOpenAI('gpt-4o-mini', { | ||
structuredOutputs: true, | ||
}), | ||
}, | ||
}) | ||
|
||
export const registry = createProviderRegistry({ | ||
ollama, | ||
openai, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { CommandContext, Context } from 'grammy' | ||
|
||
export async function start(context: CommandContext<Context>): Promise<void> { | ||
const content = 'Welcome, how can I help you?' | ||
await context.reply(content) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Composer } from 'grammy' | ||
|
||
export const onMessage = new Composer() | ||
|
||
onMessage.on('message:text', async (context) => { | ||
const userMessage = context.message.text | ||
await context.reply(userMessage) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
import { customAlphabet } from 'nanoid' | ||
|
||
export const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz0123456789') | ||
|
||
export function tomorrow(): Date { | ||
return new Date(new Date().setDate(new Date().getDate() + 1)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters