|
| 1 | +import Instructor from "@/instructor" |
| 2 | +import OpenAI from "openai" |
| 3 | +import { z } from "zod" |
| 4 | + |
| 5 | +const textBlock = ` |
| 6 | +In our recent online meeting, participants from various backgrounds joined to discuss the upcoming tech conference. The names and contact details of the participants were as follows: |
| 7 | +
|
| 8 | +- Name: John Doe, Email: [email protected], Twitter: @TechGuru44 |
| 9 | +- Name: Jane Smith, Email: [email protected], Twitter: @DigitalDiva88 |
| 10 | +- Name: Alex Johnson, Email: [email protected], Twitter: @CodeMaster2023 |
| 11 | +- Name: Emily Clark, Email: [email protected], Twitter: @InnovateQueen |
| 12 | +- Name: Ron Stewart, Email: [email protected], Twitter: @RoboticsRon5 |
| 13 | +- Name: Sarah Lee, Email: [email protected], Twitter: @AI_Aficionado |
| 14 | +- Name: Mike Brown, Email: [email protected], Twitter: @FutureTechLeader |
| 15 | +- Name: Lisa Green, Email: [email protected], Twitter: @CyberSavvy101 |
| 16 | +- Name: David Wilson, Email: [email protected], Twitter: @GadgetGeek77 |
| 17 | +- Name: Daniel Kim, Email: [email protected], Twitter: @DataDrivenDude |
| 18 | +
|
| 19 | +During the meeting, we agreed on several key points. The conference will be held on March 15th, 2024, at the Grand Tech Arena located at 4521 Innovation Drive. Dr. Emily Johnson, a renowned AI researcher, will be our keynote speaker. |
| 20 | +
|
| 21 | +The budget for the event is set at $50,000, covering venue costs, speaker fees, and promotional activities. Each participant is expected to contribute an article to the conference blog by February 20th. |
| 22 | +
|
| 23 | +A follow-up meeting is scheduled for January 25th at 3 PM GMT to finalize the agenda and confirm the list of speakers. |
| 24 | +` |
| 25 | + |
| 26 | +const ExtractionValuesSchema = z.object({ |
| 27 | + users: z |
| 28 | + .array( |
| 29 | + z.object({ |
| 30 | + name: z.string(), |
| 31 | + handle: z.string(), |
| 32 | + twitter: z.string() |
| 33 | + }) |
| 34 | + ) |
| 35 | + .min(5), |
| 36 | + date: z.string(), |
| 37 | + location: z.string(), |
| 38 | + budget: z.number(), |
| 39 | + deadline: z.string().min(1) |
| 40 | +}) |
| 41 | + |
| 42 | +export const groq = new OpenAI({ |
| 43 | + baseURL: "https://api.groq.com/openai/v1", |
| 44 | + apiKey: process.env["GROQ_API_KEY"] |
| 45 | +}) |
| 46 | + |
| 47 | +const client = Instructor({ |
| 48 | + client: groq, |
| 49 | + mode: "MD_JSON" |
| 50 | +}) |
| 51 | + |
| 52 | +let extraction = {} |
| 53 | + |
| 54 | +const extractionStream = await client.chat.completions.create({ |
| 55 | + messages: [{ role: "user", content: textBlock }], |
| 56 | + model: "llama3-70b-8192", |
| 57 | + response_model: { |
| 58 | + schema: ExtractionValuesSchema, |
| 59 | + name: "value extraction" |
| 60 | + }, |
| 61 | + stream: true |
| 62 | +}) |
| 63 | + |
| 64 | +for await (const result of extractionStream) { |
| 65 | + try { |
| 66 | + extraction = result |
| 67 | + console.clear() |
| 68 | + console.table(extraction) |
| 69 | + } catch (e) { |
| 70 | + console.log(e) |
| 71 | + break |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +console.clear() |
| 76 | +console.log("completed extraction:") |
| 77 | +console.table(extraction) |
0 commit comments