You can access search results via JSON API by adding format=json
to your query:
https://codesearch.val.run/$2?q=api&page=8&format=json
For typeahead suggestions, use the /typeahead
endpoint:
https://codesearch.val.run/typeahead?q=api
Returns an array of strings in format "username" or "username/projectName"
Found 15416 results for "api"(1009ms)
1// MEES Assistant API Endpoint with v2 API
2// Remember to add your environment variables in Val settings:
3// - OPENAI_API_KEY
4// - PINECONE_API_KEY
5// - ASSISTANT_ID
6// - PARSER_ASSISTANT_ID (optional)
11// Use OpenAI client only for embeddings
12const openai = new OpenAI({
13apiKey: Deno.env.get("OPENAI_API_KEY"),
14});
1516// Initialize Pinecone
17const pinecone = new Pinecone({
18apiKey: Deno.env.get("PINECONE_API_KEY"),
19});
2042async function parseQueryIntent(query: string) {
43try {
44const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
4546// Create a quick thread for parsing
47const threadResponse = await fetch("https://api.openai.com/v1/threads", {
48method: "POST",
49headers: {
50"Authorization": `Bearer ${OPENAI_API_KEY}`,
51"Content-Type": "application/json",
52"OpenAI-Beta": "assistants=v2",
5859// Add the query
60await fetch(`https://api.openai.com/v1/threads/${thread.id}/messages`, {
61method: "POST",
62headers: {
63"Authorization": `Bearer ${OPENAI_API_KEY}`,
64"Content-Type": "application/json",
65"OpenAI-Beta": "assistants=v2",
7273// Run the parser assistant
74const runResponse = await fetch(`https://api.openai.com/v1/threads/${thread.id}/runs`, {
75method: "POST",
76headers: {
77"Authorization": `Bearer ${OPENAI_API_KEY}`,
78"Content-Type": "application/json",
79"OpenAI-Beta": "assistants=v2",
100101const statusResponse = await fetch(
102`https://api.openai.com/v1/threads/${thread.id}/runs/${run.id}`,
103{
104headers: {
105"Authorization": `Bearer ${OPENAI_API_KEY}`,
106"OpenAI-Beta": "assistants=v2",
107},
114// Get the response
115const messagesResponse = await fetch(
116`https://api.openai.com/v1/threads/${thread.id}/messages?order=desc&limit=1`,
117{
118headers: {
119"Authorization": `Bearer ${OPENAI_API_KEY}`,
120"OpenAI-Beta": "assistants=v2",
121},
414}
415416const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
417if (!OPENAI_API_KEY) {
418throw new Error("OPENAI_API_KEY not found in environment variables");
419}
420423}
424425// IMPORTANT: All OpenAI API calls use these headers with assistants=v2
426const baseHeaders = {
427"Authorization": `Bearer ${OPENAI_API_KEY}`,
428"Content-Type": "application/json",
429"OpenAI-Beta": "assistants=v2",
466let thread;
467if (threadId) {
468const threadResponse = await fetch(`https://api.openai.com/v1/threads/${threadId}`, {
469headers: baseHeaders,
470});
474thread = await threadResponse.json();
475} else {
476const threadResponse = await fetch("https://api.openai.com/v1/threads", {
477method: "POST",
478headers: baseHeaders,
499500// Add message to thread with v2 headers
501const messageResponse = await fetch(`https://api.openai.com/v1/threads/${thread.id}/messages`, {
502method: "POST",
503headers: baseHeaders,
513514// Run the assistant with v2 headers
515const runResponse = await fetch(`https://api.openai.com/v1/threads/${thread.id}/runs`, {
516method: "POST",
517headers: baseHeaders,
652});
653654result.all_maps.forEach(mapId => {
655if (mapId && !autoDisplayMedia.find(m => m.id === mapId)) {
656autoDisplayMedia.push({
657id: mapId,
658type: "map",
659title: MEDIA_TITLES[mapId] || `Map ${mapId}`,
660article_id: result.article_id,
661relevance: `From: ${result.title.substring(0, 50)}... (${result.date})`,
748749const statusResponse = await fetch(
750`https://api.openai.com/v1/threads/${thread.id}/runs/${run.id}`,
751{ headers: baseHeaders },
752);
777// Submit tool outputs with v2 headers
778const toolOutputResponse = await fetch(
779`https://api.openai.com/v1/threads/${thread.id}/runs/${run.id}/submit_tool_outputs`,
780{
781method: "POST",
801// Get the assistant's response with v2 headers
802const messagesResponse = await fetch(
803`https://api.openai.com/v1/threads/${thread.id}/messages?order=desc&limit=20`,
804{ headers: baseHeaders },
805);
33}
3435// Fetch data from API
36const [featuredResponse, recentResponse] = await Promise.all([
37fetch('/api/listings/featured?limit=6'),
38fetch('/api/listings?limit=8')
39]);
40