Repository navigation
feat(llm)!: add native Perplexity Agent API support #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Johnson-f
wants to merge
7
commits into
tinyhumansai:main
Choose a base branch
from
Johnson-f:feat/perplexity-agent
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c8441a1
feat(llm)!: add native Perplexity Agent API support
Johnson-f 4ace3d3
fix(llm): preserve stream progress and validate hosted tool choices
Johnson-f 379aa62
fix(llm): attach the full partial response to mid-stream failures
Johnson-f 3ae2bf6
feat(llm): map OpenAI Responses output items and execution metadata
Johnson-f c7b7952
fix(llm): require declared hosted tool choices and reject shadowed fu…
Johnson-f 00380d5
chore(llm): name canonical Perplexity lifecycle routes and scope test…
Johnson-f d18a997
Merge upstream main into feat/perplexity-agent
Johnson-f File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
66 changes: 66 additions & 0 deletions
66
crates/tinyinference-llm/examples/perplexity_function_replay.rs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| //! Run a Google function call and replay its result through Perplexity. | ||
| //! | ||
| //! Set `PERPLEXITY_API_KEY`, then run: | ||
| //! `cargo run -p tinyinference-llm --example perplexity_function_replay`. | ||
| //! This makes two billable requests and runs one local demonstration function. | ||
|
|
||
| use serde_json::json; | ||
| use tinyinference_llm::{ | ||
| ChatModel, ContentBlock, ExecutionStatus, Message, ModelRequest, PerplexityModel, | ||
| PerplexitySelection, ToolSchema, message::ToolMessage, model::ToolChoice, | ||
| }; | ||
|
|
||
| #[tokio::main] | ||
| async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
| let key = std::env::var("PERPLEXITY_API_KEY")?; | ||
| let model = PerplexityModel::new( | ||
| key, | ||
| PerplexitySelection::Model("google/gemini-3.1-flash-lite".into()), | ||
| )?; | ||
| let tool = ToolSchema::new( | ||
| "lookup_code", | ||
| "Return the verification code for a record", | ||
| json!({ | ||
| "type": "object", | ||
| "properties": {"id": {"type": "integer"}}, | ||
| "required": ["id"], | ||
| "additionalProperties": false | ||
| }), | ||
| ); | ||
| let mut request = ModelRequest::new(vec![Message::user( | ||
| "Use lookup_code for record 7, then tell me its verification code.", | ||
| )]) | ||
| .with_tools(vec![tool]) | ||
| .with_tool_choice(ToolChoice::Tool("lookup_code".into())) | ||
| .with_max_tokens(512); | ||
| request.timeout_ms = Some(60_000); | ||
| let first = model.invoke(&(), request.clone()).await?; | ||
| let execution = first.execution.as_ref().ok_or("missing model identity")?; | ||
| if execution.status != ExecutionStatus::Completed || first.message.tool_calls.is_empty() { | ||
| return Err("expected a completed function call".into()); | ||
| } | ||
|
|
||
| // Replay the original assistant call so its argument bytes and signature survive. | ||
| request | ||
| .messages | ||
| .push(Message::Assistant(first.message.clone())); | ||
| for call in &first.message.tool_calls { | ||
| if call.invalid.is_some() | ||
| || call.name != "lookup_code" | ||
| || call.arguments.get("id").and_then(serde_json::Value::as_u64) != Some(7) | ||
| { | ||
| return Err("unexpected function or invalid arguments".into()); | ||
| } | ||
| let result = ToolMessage::for_call(call, vec![ContentBlock::Text("CODE_7391".into())]); | ||
| request.messages.push(Message::Tool(result)); | ||
| } | ||
| request.model = Some(execution.model.clone()); | ||
| request.continuation_id = None; | ||
| request.tool_choice = ToolChoice::None; | ||
| let response = model.invoke(&(), request).await?; | ||
| println!("{}", response.text()); | ||
| if !response.text().contains("CODE_7391") { | ||
| return Err("the model did not return the demonstration function result".into()); | ||
| } | ||
| Ok(()) | ||
| } |
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.