Skip to content

Commit

Permalink
proura脱却
Browse files Browse the repository at this point in the history
  • Loading branch information
eatski committed Aug 12, 2024
1 parent 23b7882 commit e7bb876
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 131 deletions.
45 changes: 0 additions & 45 deletions src/libs/proura/index.test.ts

This file was deleted.

59 changes: 0 additions & 59 deletions src/libs/proura/index.ts

This file was deleted.

53 changes: 26 additions & 27 deletions src/server/services/answer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@ import {
calculateEuclideanDistance,
} from "../../../libs/math";
import { openai } from "../../../libs/openai";
import { prepareProura } from "../../../libs/proura";
import { Story } from "../../../server/model/story";
import { createPrompt } from "./createPrompt";

export const checkAnswer = async (answer: string, story: Story) => {
const proura = prepareProura();
return proura
.add("distance", async () => {
const {
data: [textA, textB],
} = await openai.embeddings.create({
model: "text-embedding-ada-002",
input: [story.simpleTruth, answer],
});
const distance = openai.embeddings
.create({
model: "text-embedding-ada-002",
input: [story.simpleTruth, answer],
})
.then(({ data: [textA, textB] }) => {
if (!textA || !textB) {
return FALLBACK_DISTANCE;
}
Expand All @@ -26,21 +22,20 @@ export const checkAnswer = async (answer: string, story: Story) => {
textB.embedding,
);
return Math.round(distanceVal * 100) / 100;
})
.add("isCorrect", async () => {
const systemPrompt = await createPrompt(story.simpleTruth);
const { content } = await createMessage({
model: "claude-3-opus-20240229",
system: systemPrompt,
messages: [
{
role: "user",
content: answer,
},
],
temperature: 0.0,
max_tokens: 8,
});
});
const isCorrect = createPrompt(story.simpleTruth).then((systemPrompt) =>
createMessage({
model: "claude-3-opus-20240229",
system: systemPrompt,
messages: [
{
role: "user",
content: answer,
},
],
temperature: 0.0,
max_tokens: 8,
}).then(({ content }) => {
const text = content[0]?.type === "text" ? content[0].text : null;
const result = (["Correct", "Incorrect"] as const).find((word) =>
text?.includes(word),
Expand All @@ -49,6 +44,10 @@ export const checkAnswer = async (answer: string, story: Story) => {
throw new Error(`Unexpected response from Claude: ${content}`);
}
return result === "Correct";
})
.exec();
}),
);
return {
isCorrect: await isCorrect,
distance: await distance,
};
};

0 comments on commit e7bb876

Please sign in to comment.