Update dependencies, enhance AI integration, and improve email content
Some checks failed
Deploy / deploy (push) Failing after 1h35m43s
Some checks failed
Deploy / deploy (push) Failing after 1h35m43s
- Added @google/genai dependency for enhanced AI capabilities. - Updated CI workflow to include new environment variables for AI integration. - Refactored AI client to support multiple providers and improved key management. - Enhanced email templates for better user engagement and clarity. - Updated error handling in AI-related functions to provide clearer feedback. - Made various improvements to the application structure and code clarity.
This commit is contained in:
@@ -3,7 +3,8 @@ import type { NextRequest } from "next/server";
|
||||
import { getSession } from "@/lib/session";
|
||||
import { appDb, schema } from "@/lib/appdb";
|
||||
import { spendCreditForMessage, grantCredits } from "@/lib/credits";
|
||||
import { getAnthropic, SOHBET_MODEL, SORUMLULUK_REDDI } from "@/lib/ai/client";
|
||||
import { anahtarVar, SORUMLULUK_REDDI } from "@/lib/ai/client";
|
||||
import { sohbetAkisi } from "@/lib/ai/cagri";
|
||||
import { listeOzetiCikar, type RaporSonuc } from "@/lib/ai/rapor";
|
||||
import type { RaporParams } from "@/lib/rapor-havuzu";
|
||||
import { secimOzeti } from "@/lib/sihirbaz";
|
||||
@@ -183,15 +184,11 @@ export async function POST(request: NextRequest) {
|
||||
});
|
||||
|
||||
// Dev'de API key yoksa danışman mock cevap stream'ler (prod'da asla)
|
||||
if (
|
||||
process.env.NODE_ENV !== "production" &&
|
||||
!process.env.ANTHROPIC_API_KEY &&
|
||||
!process.env.ANTHROPIC_AUTH_TOKEN
|
||||
) {
|
||||
if (process.env.NODE_ENV !== "production" && !anahtarVar()) {
|
||||
const mockEncoder = new TextEncoder();
|
||||
const mockUserId = session.user.id;
|
||||
const cevap =
|
||||
`(Dev mock — ANTHROPIC_API_KEY tanımlı değil.) Sorunu aldım: "${mesaj.slice(0, 120)}". ` +
|
||||
`(Dev mock — Yapay Zeka anahtarı tanımlı değil.) Sorunu aldım: "${mesaj.slice(0, 120)}". ` +
|
||||
`Gerçek danışman burada listen ve seçimlerin bağlamında yanıt verecek. ` +
|
||||
`${SORUMLULUK_REDDI}`;
|
||||
const mockReadable = new ReadableStream({
|
||||
@@ -219,17 +216,14 @@ export async function POST(request: NextRequest) {
|
||||
});
|
||||
}
|
||||
|
||||
let client;
|
||||
try {
|
||||
client = getAnthropic();
|
||||
} catch {
|
||||
if (!anahtarVar()) {
|
||||
await grantCredits({
|
||||
userId: session.user.id,
|
||||
delta: 1,
|
||||
reason: "refund",
|
||||
refId: kullaniciMesajId,
|
||||
});
|
||||
console.error("[soru] Yapay Zeka istemcisi kurulamadı (anahtar eksik olabilir)");
|
||||
console.error("[soru] Yapay Zeka anahtarı tanımlı değil");
|
||||
return Response.json(
|
||||
{
|
||||
error:
|
||||
@@ -250,36 +244,20 @@ export async function POST(request: NextRequest) {
|
||||
const encoder = new TextEncoder();
|
||||
const userId = session.user.id;
|
||||
|
||||
let stream;
|
||||
try {
|
||||
stream = client.messages.stream({
|
||||
model: SOHBET_MODEL,
|
||||
max_tokens: 1024,
|
||||
system,
|
||||
messages: mesajlar,
|
||||
});
|
||||
} catch {
|
||||
await grantCredits({ userId, delta: 1, reason: "refund", refId: kullaniciMesajId });
|
||||
return Response.json({ error: "Yapay Zeka'ya ulaşılamadı." }, { status: 502 });
|
||||
}
|
||||
|
||||
const readable = new ReadableStream({
|
||||
async start(controller) {
|
||||
let tamamlandi = false;
|
||||
try {
|
||||
for await (const event of stream) {
|
||||
if (
|
||||
event.type === "content_block_delta" &&
|
||||
event.delta.type === "text_delta"
|
||||
) {
|
||||
controller.enqueue(encoder.encode(event.delta.text));
|
||||
}
|
||||
// Sağlayıcıya bağlanma hatası da ilk parçada burada yakalanır
|
||||
let metin = "";
|
||||
for await (const parca of sohbetAkisi({
|
||||
system,
|
||||
mesajlar,
|
||||
maxTokens: 1024,
|
||||
})) {
|
||||
metin += parca;
|
||||
controller.enqueue(encoder.encode(parca));
|
||||
}
|
||||
const final = await stream.finalMessage();
|
||||
const metin = final.content
|
||||
.filter((b) => b.type === "text")
|
||||
.map((b) => b.text)
|
||||
.join("");
|
||||
await appDb.insert(schema.chatMessages).values({
|
||||
id: crypto.randomUUID(),
|
||||
userId,
|
||||
|
||||
Reference in New Issue
Block a user