Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/tools/contentProcessing.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { config } from '../config';
import cheerio from 'cheerio';
import * as cheerio from 'cheerio';
import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter';
import { MemoryVectorStore } from 'langchain/vectorstores/memory';
import { Document as DocumentInterface } from 'langchain/document';
Expand Down Expand Up @@ -104,4 +104,4 @@ export async function processAndVectorizeContent(
console.error('Error processing and vectorizing content:', error);
throw error;
}
}
}
4 changes: 2 additions & 2 deletions app/tools/mentionFunctions/portKeyAIGateway.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Portkey from 'portkey-ai';
import { config } from '../../config';

export async function portKeyAIGateway(mentionTool: string, userMessage: string, streamable: any): Promise<void> {
if (config.usePortkey) {
const { default: Portkey } = await import('portkey-ai');
const portkey = new Portkey({
apiKey: process.env.PORTKEY_API_KEY,
virtualKey: process.env.PORTKEY_BEDROCK_VIRTUAL_KEY
Expand Down Expand Up @@ -36,4 +36,4 @@ export async function portKeyAIGateway(mentionTool: string, userMessage: string,
}
// Ensure the function returns void
return;
}
}
4 changes: 2 additions & 2 deletions app/tools/mentionFunctions/portKeyAIGatewayTogetherAI.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Portkey from 'portkey-ai';
import { config } from '../../config';

export async function portKeyAIGatewayTogetherAI(mentionTool: string, userMessage: string, streamable: any): Promise<void> {
if (config.usePortkey) {
const { default: Portkey } = await import('portkey-ai');
const portkey = new Portkey({
apiKey: process.env.PORTKEY_API_KEY,
virtualKey: 'together-ai-cc4094'
Expand Down Expand Up @@ -36,4 +36,4 @@ export async function portKeyAIGatewayTogetherAI(mentionTool: string, userMessag
}
// Ensure the function returns void
return;
}
}
27 changes: 23 additions & 4 deletions app/tools/mentionFunctions/structuredUnlockSummarize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@
import OpenAI from "openai";
import { zodResponseFormat } from "openai/helpers/zod";
import { z } from "zod";
import { config } from '../../config';

// 2. Initialize OpenAI client
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
let openai: OpenAI;
if (config.useOllamaInference) {
openai = new OpenAI({
baseURL: 'http://localhost:11434/v1',
apiKey: 'ollama'
});
} else {
openai = new OpenAI({
baseURL: config.nonOllamaBaseURL,
apiKey: config.inferenceAPIKey
});
}

// Define Zod schema for URL extraction
const UrlExtraction = z.object({
Expand All @@ -18,7 +30,7 @@ export async function brightDataWebScraper(mentionTool: string, userMessage: str
let targetUrl: string;
try {
// 4. Extract URL from user message using parsed output feature
const urlCompletion = await openai.beta.chat.completions.parse({
const urlCompletion = await openai.chat.completions.create({
model: "gpt-4o-2024-08-06",
messages: [
{ role: "system", content: "Extract the most likely valid URL from a natural language query." },
Expand All @@ -28,7 +40,14 @@ export async function brightDataWebScraper(mentionTool: string, userMessage: str
});

// 5. Parse and validate URL data
const extractedUrl = urlCompletion.choices[0]?.message?.parsed?.url ?? '';
const messageContent = urlCompletion.choices[0]?.message?.content ?? '';
let extractedUrl = '';
try {
const parsedContent = JSON.parse(messageContent);
extractedUrl = parsedContent.url ?? '';
} catch {
extractedUrl = '';
}

if (!extractedUrl) {
streamable.update({ llmResponse: `No valid URL found in the user message \n\n` });
Expand Down Expand Up @@ -96,4 +115,4 @@ export async function brightDataWebScraper(mentionTool: string, userMessage: str
// Error handling for stream update failure
}
}
}
}
5 changes: 3 additions & 2 deletions app/tools/rateLimiting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ if (config.useRateLimiting) {

export async function checkRateLimit(streamable: any) {
if (config.useRateLimiting && ratelimit) {
const identifier = headers().get('x-forwarded-for') || headers().get('x-real-ip') || headers().get('cf-connecting-ip') || headers().get('client-ip') || "";
const headersList = await headers();
const identifier = headersList.get('x-forwarded-for') || headersList.get('x-real-ip') || headersList.get('cf-connecting-ip') || headersList.get('client-ip') || "";
const { success } = await ratelimit.limit(identifier);
streamable.done({ 'status': 'rateLimitReached' });
return success;
}
return true;
}
}
2 changes: 1 addition & 1 deletion lib/hooks/use-enter-submit.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useRef, type RefObject } from 'react';

export function useEnterSubmit(): {
formRef: RefObject<HTMLFormElement>;
formRef: RefObject<HTMLFormElement | null>;
onKeyDown: (event: React.KeyboardEvent<HTMLTextAreaElement>) => void;
} {
const formRef = useRef<HTMLFormElement>(null);
Expand Down
2 changes: 1 addition & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
Loading