{"id":25979473,"url":"https://github.com/neofox/gleamstral","last_synced_at":"2026-03-10T00:31:10.610Z","repository":{"id":279910358,"uuid":"940407524","full_name":"Neofox/gleamstral","owner":"Neofox","description":"Gleamstral is a API Client for the Mistral API written in Gleam","archived":false,"fork":false,"pushed_at":"2025-08-01T06:43:15.000Z","size":135,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-01T16:37:04.402Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Gleam","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Neofox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-02-28T05:50:47.000Z","updated_at":"2025-07-27T12:09:18.000Z","dependencies_parsed_at":"2025-02-28T13:10:52.342Z","dependency_job_id":"fa63f838-6cf0-4e23-af14-f5e153dddb9b","html_url":"https://github.com/Neofox/gleamstral","commit_stats":null,"previous_names":["neofox/gleamstral"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/Neofox/gleamstral","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neofox%2Fgleamstral","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neofox%2Fgleamstral/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neofox%2Fgleamstral/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neofox%2Fgleamstral/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Neofox","download_url":"https://codeload.github.com/Neofox/gleamstral/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neofox%2Fgleamstral/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30318376,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T20:05:46.299Z","status":"ssl_error","status_checked_at":"2026-03-09T19:57:04.425Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-05T06:31:25.254Z","updated_at":"2026-03-10T00:31:10.390Z","avatar_url":"https://github.com/Neofox.png","language":"Gleam","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gleamstral\n\n[![Package Version](https://img.shields.io/hexpm/v/gleamstral)](https://hex.pm/packages/gleamstral)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/gleamstral/)\n\nA Gleam client library for the Mistral AI API, providing type-safe access to Mistral's powerful language models, embeddings, and agents.\n\n## Overview\n\nGleamstral enables Gleam applications to seamlessly integrate with Mistral AI's capabilities, including:\n\n- Chat completions with various Mistral models (Large, Small, Ministral, etc.)\n- Function/tool calling support\n- Embeddings generation\n- Agent API integration\n- Image analysis with Pixtral models\n\nFurther documentation can be found at \u003chttps://hexdocs.pm/gleamstral\u003e.\n\n## Installation\n\n```sh\ngleam add gleamstral\n```\n\n## Getting an API key\n\nYou can get an API key **for free** from Mistral [La Plateforme](https://console.mistral.ai/).\n\n## Quick Example\n\n```gleam\nimport gleam/io\nimport gleam/httpc\nimport gleam/list\nimport gleamstral/client\nimport gleamstral/chat\nimport gleamstral/message\nimport gleamstral/model\n\npub fn main() {\n  // Create a Mistral client with your API key\n  let client = client.new(\"your-mistral-api-key\")\n\n  // Set up a chat with Mistral Large model\n  let chat_client = chat.new(client) |\u003e chat.set_temperature(0.7)\n\n  // Define a list of one or many messages to send to the model\n  let messages = [\n    message.UserMessage(message.TextContent(\"Explain brievly what is Gleam\")),\n  ]\n\n  // Send the request and get a response from the model\n  let assert Ok(response) =\n    chat_client\n    |\u003e chat.complete_request(model.MistralSmall, messages)\n    |\u003e httpc.send\n\n  let assert Ok(response) = chat.handle_response(response)\n  let assert Ok(choice) = list.first(response.choices)\n  let assert message.AssistantMessage(content, _, _) = choice.message\n\n  io.println(\"Response: \" \u003c\u003e content) // \"Gleam is a very cool language [...]\"\n}\n```\n\n## Key Features\n\n### Chat Completions with Vision\n\nGleamstral supports multimodal inputs, allowing you to send both text and images to vision-enabled models like Pixtral:\n\n```gleam\n// Create a message with an image\nlet messages = [\n  message.UserMessage(\n    message.MultiContent([\n      message.Text(\"What's in this image?\"),\n      message.ImageUrl(\"https://gleam.run/images/lucy/lucy.svg\")\n    ])\n  )\n]\n\n// Use a Pixtral model for image analysis\nlet assert Ok(response) =\n  chat.new(client)\n  |\u003e chat.complete_request(model.PixtralLarge, messages)\n  |\u003e httpc.send\n\nlet assert Ok(response) = chat.handle_response(response)\n// Get the first choice from the response\nlet assert Ok(choice) = list.first(response.choices)\nlet assert message.AssistantMessage(content, _, _) = choice.message\n\nio.println(\"Response: \" \u003c\u003e content) // \"This is a picture of the cute star lucy\"\n```\n\n### Agent API\n\nAccess Mistral's Agent API to utilize pre-configured agents for specific tasks:\n\n```gleam\n// Get your agent ID from the Mistral console\nlet agent_id = \"your-agent-id\"\n\n// Call the agent with your agent ID and messages\nlet assert Ok(response) =\n  agent.new(client)\n  |\u003e agent.complete_request(agent_id, messages)\n  |\u003e httpc.send\n\nlet assert Ok(response) = agent.handle_response(response)\n```\n\n### Embeddings Generation\n\nGenerate vector embeddings for text to enable semantic search, clustering, or other vector operations:\n\n```gleam\n// Generate embeddings for a text input\nlet assert Ok(response) =\n  embeddings.new(client)\n  |\u003e embeddings.create_request(model.MistralEmbed, [\"Your text to embed\"])\n  |\u003e httpc.send\n\nlet assert Ok(response) = embeddings.handle_response(response)\n```\n\n### Tool/Function Calling\n\nDefine tools that the model can use to call functions in your application:\n\n```gleam\n// Define a tool\nlet weather_tool = tool.new_basic_function(\n  \"get_weather\",\n  \"Get the current weather in a location\",\n  [\n    #(\"location\", StringProperty(\"the name of the city\")),\n    #(\"unit\", StringProperty(\"the unit to use for the temp. F or C\"))\n  ]\n)\n\n// Create a chat client with the tool\nlet assert Ok(response) =\n  chat.new(client)\n  |\u003e chat.set_tools([weather_tool])\n  |\u003e chat.complete_request(model.MistralSmall, messages)\n  |\u003e httpc.send\n\nlet assert Ok(response) = chat.handle_response(response)\n```\n\n### Structured Outputs\n\nReceive structured outputs from the model, based on a JSON schema:\n\n```gleam\npub type Book {\n  Book(name: String, authors: List(String))\n}\n\nfn book_decoder() -\u003e blueprint.Decoder(Book) {\n  blueprint.decode2(\n    Book,\n    blueprint.field(\"name\", blueprint.string()),\n    blueprint.field(\"authors\", blueprint.list(blueprint.string())),\n  )\n}\nlet json_schema = blueprint.generate_json_schema(book_decoder())\n\n// Create a chat client with structured output\nlet assert Ok(response) =\n  chat.new(client)\n  |\u003e chat.set_response_format(chat.JsonSchema(\n      schema: json_schema,\n      name: \"book\",\n    ))\n  |\u003e chat.complete_request(model.MistralSmall, messages)\n  |\u003e httpc.send\n```\n\n## Examples\n\nThe `examples/` directory contains several ready-to-use examples demonstrating the library's capabilities:\n\n- `text_completion.gleam`: Basic text completion example\n- `agent.gleam`: Shows how to use the Mistral Agent API\n- `basic_tool.gleam`: Demonstrates tool/function calling functionality\n- `embeddings.gleam`: Illustrates how to generate and use embeddings\n- `image_analysis.gleam`: Shows how to perform image analysis with Pixtral models\n- `json_object.gleam`: Example of JSON output from the model\n- `structured_output.gleam`: Demonstrates how to use structured outputs\n\nTo run any example:\n\n```sh\ncd examples\ngleam run -m example_name  # e.g., gleam run -m agent\n```\n\nNote: You'll need to set your Mistral API key in an `.env` file or as an environment variable.\n\n## Roadmap\n\n- [x] Decouple the HTTP client from the library\n- [x] Add support for structured outputs (JSON, JSON Schema, etc.)\n- [x] Improve tool calling support\n- [ ] Add example for streaming responses\n- [ ] Add more tests and documentation\n\n## Contributing\n\nContributions are welcome! Please open an issue or submit a pull request.\n\n## License\n\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneofox%2Fgleamstral","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneofox%2Fgleamstral","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneofox%2Fgleamstral/lists"}