import { OpenAI } from "https://esm.town/v/std/openai";
const openai = new OpenAI();
export default async function main(req: Request): Promise<Response> {
if (req.method !== "POST") {
return new Response("Method not allowed. Use POST with text in the body.", { status: 405 });
}
const text = await req.text();
const completion = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [
{
role: "system",
content: "Given a chunk of content, create a list of relationships in this specific format: [entity1_type:entity1_name] -[:RELATIONSHIP_TYPE]-> [entity2_type:entity2_name]. Output each relationship on a new line."
},
{ role: "user", content: text }
],
temperature: 0.7,
max_tokens: 200,
});
const relationships = completion.choices[0].message.content.trim();
return new Response(relationships, {
headers: { "Content-Type": "text/plain" }
});
}