-
-
Save up1/87b72e470843dc5553841206ccc16e5e to your computer and use it in GitHub Desktop.
Hello Jev
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { choice, TypeSafeClient } from "@typesafe-ai/sdk"; | |
| const client = new TypeSafeClient(); | |
| const response = await client.systemOne({ | |
| state: { document: "I was charged twice. Please fix this ASAP." }, | |
| questions: { | |
| category: choice("What is this ticket about?", { | |
| billing: null, | |
| technical: null, | |
| other: null, | |
| }), | |
| }, | |
| }); | |
| console.log(response.answers.category.choice); | |
| console.log(response); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $npm install @typesafe-ai/sdk | |
| $export export TYPESAFE_API_KEY=apikey_xxxxx | |
| $node 1.js | |
| billing | |
| { | |
| model: 'jev-1.13.0', | |
| answers: { | |
| category: { | |
| type: 'choice', | |
| choice: 'billing', | |
| confidence: 1, | |
| probabilities: [Object] | |
| } | |
| }, | |
| usage: { input_tokens: 310, output_tokens: 38 } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from langchain_typesafe import Noul, TypeSafeClassifier | |
| classifier = TypeSafeClassifier() | |
| response = classifier.invoke( | |
| state=( | |
| "The deploy failed twice and customers are seeing 500s. " | |
| "Can someone look now?" | |
| ), | |
| questions={ | |
| "urgent": Noul( | |
| instructions="Does this need attention right now?" | |
| ), | |
| }, | |
| ) | |
| urgency = response.nouls["urgent"].noul | |
| print(urgency) | |
| print(response) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { choice, TypeSafeClient } from "@typesafe-ai/sdk"; | |
| const client = new TypeSafeClient(); | |
| const response = await client.systemOne({ | |
| "state": { | |
| "source_text": "Invoice #4471 issued March 3, 2026 to Beaver Dam Logistics for $12,840.00, net 30." | |
| }, | |
| "questions": { | |
| "invoice_number_is_correct": { | |
| "type": "noul", | |
| "instructions": { | |
| "field": { | |
| "name": "invoice_number", | |
| "type": "string", | |
| "description": "The identifier printed on the invoice." | |
| }, | |
| "extracted_value": "4471", | |
| "question": "Does `extracted_value` match the `field` as it appears in `source_text`?" | |
| } | |
| }, | |
| "customer_name": { | |
| "type": "choice", | |
| "instructions": { | |
| "field": { | |
| "name": "customer_name", | |
| "type": "string", | |
| "description": "The organization the invoice was issued to." | |
| }, | |
| "question": "Which option is the value of `field` in `source_text`?" | |
| }, | |
| "criteria": { | |
| "Beaver Logistics": null, | |
| "Dam Logistics": null, | |
| "Beaver Dam Logistics": null, | |
| "Beaver": null, | |
| "Dam": null | |
| } | |
| }, | |
| "amount_due": { | |
| "type": "score", | |
| "instructions": { | |
| "field": { | |
| "name": "amount_due", | |
| "type": "number", | |
| "unit": "USD", | |
| "description": "The total the invoice asks to be paid." | |
| }, | |
| "question": "How large is the `field` value in `source_text`?" | |
| }, | |
| "criteria": [ | |
| "Under $1,000", | |
| "$1,000 to $10,000", | |
| "$10,000 to $100,000", | |
| "$100,000 to $1,000,000", | |
| "Over $1,000,000" | |
| ] | |
| }, | |
| "payment_terms": { | |
| "type": "score", | |
| "instructions": { | |
| "field": { | |
| "name": "payment_terms", | |
| "type": "integer", | |
| "unit": "days", | |
| "description": "Days allowed for payment, from terms such as \"net 30\"." | |
| }, | |
| "question": "How many days does the `field` in `source_text` allow for payment?" | |
| }, | |
| "criteria": [ | |
| "Due on receipt", | |
| "Net 10", | |
| "Net 30", | |
| "Net 60", | |
| "Net 90" | |
| ] | |
| } | |
| } | |
| }); | |
| console.log(response.answers.invoice_number_is_correct.choice); | |
| console.log(response.answers.customer_name.choice); | |
| console.log(response.answers.amount_due.choice); | |
| console.log(response.answers.payment_terms.choice); | |
| console.log(response); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from langchain.agents import create_agent | |
| from langchain_typesafe.experimental.middleware import ( | |
| ModelChoice, | |
| ModelRouterMiddleware, | |
| ) | |
| router = ModelRouterMiddleware( | |
| choices={ | |
| "fast": ModelChoice( | |
| model="openai:gpt-5.6-terra", | |
| criteria="Direct lookups, extraction, and localized changes with explicit targets.", | |
| ), | |
| "powerful": ModelChoice( | |
| model="openai:gpt-6-astra", | |
| criteria="Architecture, novel root-cause reasoning, and high-stakes decisions.", | |
| ), | |
| }, | |
| instructions="Choose the least costly model that can complete the task safely.", | |
| ) | |
| agent = create_agent("openai:gpt-5.6-terra", middleware=[router]) | |
| result = agent.invoke( | |
| { | |
| "messages": [ | |
| { | |
| "role": "user", | |
| "content": "Prove that there are infinitely many prime numbers.", | |
| } | |
| ] | |
| } | |
| ) | |
| print(result["model_route"].choice) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment