-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
90 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,62 @@ | ||
module Perplexity | ||
|
||
open FsHttp | ||
open ServerSentEvents | ||
|
||
open Configuration | ||
open Navigation | ||
open GtkGui | ||
|
||
|
||
type Usage = | ||
{ prompt_tokens: int | ||
completion_tokens: int | ||
total_tokens: int } | ||
|
||
type PerplexityMessage = { role: string; content: string } | ||
type Delta = { role: string; content: string } | ||
|
||
type PerplexityChoice = | ||
{ index: int | ||
finish_reason: string option | ||
message: PerplexityMessage | ||
delta: Delta } | ||
|
||
type Message = | ||
{ id: string | ||
model: obj option | ||
created: uint64 | ||
usage: Usage | ||
object: string | ||
choices: PerplexityChoice list } | ||
|
||
let deserializeActive (json: string) = | ||
try | ||
System.Text.Json.JsonSerializer.Deserialize<Message> json |> Some | ||
with _ -> | ||
None | ||
|
||
|
||
let eventLineToMsg (line: EventLine) = | ||
match line with | ||
| Data d -> | ||
match deserializeActive d with | ||
| Some { choices = x :: _ } -> Some(Word x.delta.content) | ||
| _ -> None | ||
| _ -> None | ||
|
||
let ask (Key key) (Model model) (prompt: string) = | ||
http { | ||
POST "https://api.perplexity.ai/chat/completions" | ||
AuthorizationBearer key | ||
body | ||
|
||
jsonSerialize | ||
{| model = model | ||
max_tokens = 9000 | ||
stream = true | ||
messages = [ {| role = "user"; content = prompt |} ] |} | ||
} | ||
|> Request.send | ||
|> Response.toStream | ||
|> chooseEvents eventLineToMsg |
This file contains 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 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 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 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