-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add /api/ai/suggests and SuggestByCurrentLocation component
- Loading branch information
Showing
11 changed files
with
558 additions
and
125 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,45 @@ | ||
import { NextResponse } from "next/server"; | ||
import { OpenAIChat } from "langchain/llms/openai"; | ||
import { loadTridentSuggestChain } from "@/utils/langchain/chains/suggest"; | ||
import { OpenAIEmbeddings } from "langchain/embeddings/openai"; | ||
|
||
export async function POST(request: Request) { | ||
const res = await request.json(); | ||
const query = res.query; | ||
|
||
let embeddings: OpenAIEmbeddings; | ||
let llm: OpenAIChat; | ||
if (process.env.CLOUDFLARE_AI_GATEWAY) { | ||
embeddings = new OpenAIEmbeddings({ | ||
configuration: { | ||
baseURL: process.env.CLOUDFLARE_AI_GATEWAY + "/openai", | ||
}, | ||
}); | ||
llm = new OpenAIChat({ | ||
configuration: { | ||
baseURL: process.env.CLOUDFLARE_AI_GATEWAY + "/openai", | ||
}, | ||
temperature: 0, | ||
}); | ||
} else { | ||
embeddings = new OpenAIEmbeddings(); | ||
llm = new OpenAIChat({ temperature: 0 }); | ||
} | ||
|
||
const chain = await loadTridentSuggestChain({ embeddings, llm }); | ||
const result = await chain.call({ input: query }); | ||
|
||
console.log("----- ----- -----"); | ||
console.log("----- start suggest -----"); | ||
console.log("Human:", query); | ||
console.log("AI:", result.text); | ||
console.log(""); | ||
|
||
console.log("----- end suggest -----"); | ||
console.log("----- ----- -----"); | ||
|
||
return NextResponse.json({ | ||
query: query, | ||
suggests: result.text, | ||
}); | ||
} |
Oops, something went wrong.
763f40c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
trident – ./
trident-yuiseki-s-team.vercel.app
trident-seven.vercel.app
trident.yuiseki.net
trident-git-main-yuiseki-s-team.vercel.app