Skip to content

Commit

Permalink
Iterate
Browse files Browse the repository at this point in the history
  • Loading branch information
serefyarar committed Nov 29, 2024
1 parent 6225e4d commit b94dbf5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
20 changes: 18 additions & 2 deletions api/src/language/completions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { searchItems } from "./search_item.js";
import { zodResponseFormat } from "openai/helpers/zod";
import { jsonSchemaToZod } from "json-schema-to-zod";
import tiktoken from 'tiktoken';
import { getModelInfo } from '../utils/mode.js';

const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
Expand Down Expand Up @@ -35,10 +36,14 @@ export const handleCompletions = async ({ messages, indexIds, maxDocs=500, strea
timeFilter
});

const { runtimeDefinition } = await getModelInfo();


const filteredDocs = [];
for (const doc of docs) {
let docText;
if (doc.object === "cast") {
//console.log(doc.modelId, runtimeDefinition.models.Cast.id, runtimeDefinition.models.Event.id)
if (doc.modelId === runtimeDefinition.models.Cast.id) {
const authorName = doc.author.name || doc.author.username;
const castUrl = `https://warpcast.com/${doc.author.username}/${doc.hash.substring(0, 12)}`;
const authorUrl = `https://warpcast.com/${doc.author.username}`;
Expand All @@ -51,7 +56,18 @@ export const handleCompletions = async ({ messages, indexIds, maxDocs=500, strea
`- created_at: ${doc.timestamp}`,
'----'
].join('\n');
} else {
} else if (doc.modelId == runtimeDefinition.models.Event.id) {
docText = [
'Event details:',
`- title: ${doc.title}`,
`- location: ${doc.location}`,
`- start time: ${doc.start_time}`,
`- end time: ${doc.end_time}`,
`- link: ${doc.link}`,
`- description: ${doc.description}`,
'----'
].join('\n');
} else {
docText = JSON.stringify(doc);
}

Expand Down
16 changes: 16 additions & 0 deletions api/src/utils/mode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
let modelInfo = null

export async function getModelInfo() {
if (modelInfo) {
return modelInfo
}

try {
const modelResponse = await fetch(`http://localhost:8000/model/info`);
const modelInfo = await modelResponse.json();
return modelInfo;
} catch (error) {
console.error('Error fetching model info:', error);
return null;
}
}

0 comments on commit b94dbf5

Please sign in to comment.