Crates.io | samvada |
lib.rs | samvada |
version | 0.1.2 |
source | src |
created_at | 2024-10-29 06:38:22.990168 |
updated_at | 2024-10-29 17:30:23.365557 |
description | Chat with AI assistant in markdown file |
homepage | |
repository | https://github.com/trendoraai/samvada |
max_upload_size | |
id | 1426685 |
size | 104,333 |
Samvada is a powerful command-line tool for managing AI-assisted conversations using markdown files. It offers a structured approach to create, validate, and interact with AI chat sessions while maintaining a clean, version-controllable format.
cargo install samvada
git clone https://github.com/yourusername/samvada
cd samvada
cargo build --release
Samvada uses a configuration file and supports multiple ways to provide your OpenAI API key.
config.yml
)Samvada utilizes a config.yml
file located in ~/.samvada/
to store default settings such as the system prompt, AI model, and API endpoint. If this file doesn't exist, Samvada will create it with default values when you first run the tool.
Default config.yml
:
system_prompt: "You are a helpful assistant."
model: "gpt-3.5-turbo"
api_endpoint: "https://api.openai.com/v1/chat/completions"
You can customize these settings by editing the config.yml
file:
nano ~/.samvada/config.yml
Generally, samvada uses local directory .env
file to check for keys. If not found, then it will look into the global .env
file in ~/.samvada/
.
Samvada requires an OpenAI API key to function. The API key can be provided through several methods, with the following precedence order:
--api-key
).env
File in Configuration Directory (~/.samvada/.env
)OPENAI_API_KEY
)You can provide the API key directly when running a command:
samvada chat ask my_chat.md --api-key your_api_key_here
Note: Providing the API key via the command line will create or update the .env
file in ~/.samvada/
with the provided key.
.env
FileCreate a .env
file in the Samvada configuration directory with your API key:
echo "OPENAI_API_KEY=your_api_key_here" > ~/.samvada/.env
Set the OPENAI_API_KEY
environment variable in your shell:
Linux/macOS:
export OPENAI_API_KEY=your_api_key_here
Windows (Command Prompt):
set OPENAI_API_KEY=your_api_key_here
Windows (PowerShell):
$env:OPENAI_API_KEY="your_api_key_here"
Samvada will check for the API key in the following order:
--api-key
): Highest priority..env
File (~/.samvada/.env
): If no command line argument is provided.OPENAI_API_KEY
): If neither of the above is provided.If the API key is not found, Samvada will prompt an error message indicating that the key is missing and needs to be set using one of the methods above.
# Create a new chat file with default settings
samvada chat create my_chat
# Create a chat file with a custom directory
samvada chat create my_chat --dir /path/to/directory
When creating a new chat, Samvada will use the default configurations from config.yml
to populate the frontmatter of the chat file.
# Lint a single chat file
samvada chat lint my_chat.md
# Lint all chat files in a directory
samvada chat lint ./chats
# Start or continue a chat session
samvada chat ask my_chat.md
If you have not set your API key in the .env
file or environment variable, you can pass it directly:
samvada chat ask my_chat.md --api-key your_api_key_here
Note: Providing the API key with --api-key
will store it in ~/.samvada/.env
for future use.
Chat files use markdown with YAML frontmatter to define the conversation settings and history.
Example Chat File (my_chat.md
):
---
title: My Chat
system: You are a helpful assistant.
model: gpt-3.5-turbo
api_endpoint: https://api.openai.com/v1/chat/completions
created_at: 2024-01-01T12:00:00Z
updated_at: 2024-01-01T12:00:00Z
tags: []
summary:
---
user: Hello, how can you help me today?
assistant: I'm here to assist you with any questions or tasks you might have. How can I help?
user: Here's a file, summarize it.
[[src/main.rs]]
You can override the default configurations from config.yml
by specifying them in the frontmatter of your chat file. This allows you to customize settings like system
, model
, and api_endpoint
on a per-chat basis.
Include external content in your chat by referencing files:
user: Please review this code:
[[src/main.rs]]
Note: The file path should be on a separate line, enclosed in double square brackets.
Samvada automatically generates log files alongside your chat files. These logs capture all interactions and system events, providing an audit trail for tracking and debugging.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.