Skip to content

Instantly share code, notes, and snippets.

@uratmangun
Last active December 28, 2024 13:43

Revisions

  1. uratmangun revised this gist Dec 28, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion convert-search.mjs
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ export async function searchParser(content) {
    messages: [
    {
    role: "system",
    content: "You're search results parser. You're given a search results HTML page and you're tasked with parsing the results and returning a json array of objects with the following fields: title and url."
    content: "You're search results parser. You're given a search results HTML page and you're tasked with parsing the results and returning a json array of objects with the following fields: title, url, description."
    },
    {role: "user", content}
    ]
  2. uratmangun revised this gist Dec 28, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion convert-search.mjs
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ export async function searchParser(content) {
    messages: [
    {
    role: "system",
    content: "You're search results parser. You're given a search results HTML page and you're tasked with parsing the results and returning a json array of objects with the following fields: title, url, description."
    content: "You're search results parser. You're given a search results HTML page and you're tasked with parsing the results and returning a json array of objects with the following fields: title and url."
    },
    {role: "user", content}
    ]
  3. uratmangun revised this gist Dec 28, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion convert-search.mjs
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ export async function searchParser(content) {
    messages: [
    {
    role: "system",
    content: "You're results parser. You're given a results HTML page and you're tasked with parsing the results and returning a json array of objects with the following fields: title, url, description."
    content: "You're search results parser. You're given a search results HTML page and you're tasked with parsing the results and returning a json array of objects with the following fields: title, url, description."
    },
    {role: "user", content}
    ]
  4. uratmangun created this gist Dec 28, 2024.
    31 changes: 31 additions & 0 deletions convert-search.mjs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    import OpenAI from "openai"
    import dotenv from 'dotenv';
    import { zodResponseFormat } from "openai/helpers/zod";
    import { z } from "zod";
    dotenv.config({ path: '.env.local' });
    const openai = new OpenAI({
    baseURL: "https://generativelanguage.googleapis.com/v1beta/openai/",
    apiKey: process.env.GEMINI_API_KEY
    })
    const SearchResult = z.array(
    z.object({
    title: z.string(),
    url: z.string(),
    description: z.string(),
    })
    );
    export async function searchParser(content) {
    const completion = await openai.chat.completions.create({
    model: "gemini-2.0-flash-exp",
    response_format: zodResponseFormat(SearchResult, "search_result"),
    messages: [
    {
    role: "system",
    content: "You're results parser. You're given a results HTML page and you're tasked with parsing the results and returning a json array of objects with the following fields: title, url, description."
    },
    {role: "user", content}
    ]
    })

    return completion
    }