Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/imclerran/roc-openrouter
Roc Package for the using the OpenRouter.ai API
https://github.com/imclerran/roc-openrouter
artificial-intelligence functional-programming roc-lang
Last synced: 3 months ago
JSON representation
Roc Package for the using the OpenRouter.ai API
- Host: GitHub
- URL: https://github.com/imclerran/roc-openrouter
- Owner: imclerran
- Created: 2024-05-13T21:09:10.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-05-23T17:02:11.000Z (6 months ago)
- Last Synced: 2024-05-27T12:11:02.489Z (6 months ago)
- Topics: artificial-intelligence, functional-programming, roc-lang
- Language: Roc
- Homepage:
- Size: 74.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- roc-awesome - imclerran/roc-openrouter
README
# Roc package for the OpenRouter.ai API
[![Roc-Lang][roc_badge]][roc_link]
This package is still in WIP 🛠️ stages, so the interface may be subject to change. With that said, the package currently supports:
- Creating and parsing ChatML style requests and responses.
- Creating and parsing raw prompt style requests and responses.
- Formatting prompt strings with `[INST]`, `<>`, and `` tags for models with llama style fine-tuning.
- Easy access to over 140 up-to-date models, plus additional older models.
- Most common LLM parameters such as `temperature`, `topP`, `topK`, `repetitionPenalty`, etc.
- OpenRouter specific features like fallback models and provider preferences.## Coming (maybe not so) soon 🚀
- LLM tool use! 🔨🔧🪛⛏️🪓
- Blocked on [support for Dict type in EncoderFormatting](https://github.com/roc-lang/roc/issues/5294)## Example
```roc
import cli.Stdout
import cli.Http
import cli.Task
import ai.Chatmain =
apiKey = ""
client = Chat.initClient { apiKey, model: "openai/gpt-4o" }
messages = Chat.appendUserMessage [] "Hello, world!"
response = Http.send! (Chat.buildRequest client messages)
when Chat.decodeTopMessageChoice response.body is
Ok message -> Stdout.line message.content
Err (HttpError err) -> Stdout.line "$(Num.toStr err.code): $(err.message)"
Err _ -> Stdout.line "Error decoding API response"
```For complete example apps, including a full chatbot app, see the examples folder.
[roc_badge]: https://img.shields.io/endpoint?url=https%3A%2F%2Fpastebin.com%2Fraw%2FGcfjHKzb
[roc_link]: https://github.com/roc-lang/roc