-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update documentation; Improve Errors; Update Tests
- Loading branch information
Showing
20 changed files
with
348 additions
and
140 deletions.
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 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,27 @@ | ||
# Custom AI Integration | ||
|
||
## Overview | ||
EasyAI allows you to integrate your own AI models and services. | ||
|
||
## Registering a Custom AI Service | ||
|
||
```python | ||
from easyai.custom_ai import CustomAIService, register_custom_ai | ||
|
||
# Define a custom AI service | ||
class MyCustomAI(CustomAIService): | ||
def generate_text(self, prompt): | ||
return f"Custom AI response for: {prompt}" | ||
|
||
def text_to_speech(self, text, **kwargs): | ||
return f"Custom TTS output: {text}" | ||
|
||
# Register the custom AI | ||
register_custom_ai("my_custom_ai", MyCustomAI) | ||
|
||
# Use the custom AI | ||
custom_app = easyai.create_app(name="custom_ai_app", service="my_custom_ai") | ||
print(custom_app.request("Hello from Custom AI!")) | ||
``` | ||
|
||
Now you are ready to use and expand EasyAI for your projects! Revisit the [Installation Guide](./installation.md) if needed. |
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,20 @@ | ||
# Error Handling | ||
|
||
## Overview | ||
EasyAI includes robust error handling with clear, emoji-coded messages for quick debugging. | ||
|
||
### Common Errors | ||
- 🔐 **Missing API Key**: "No API key provided! Add your API key to initialize the service." | ||
- 🚫 **Invalid Request**: "The request is invalid. Please check your inputs." | ||
- 🌐 **Connection Error**: "Unable to connect to the API. Ensure the server is running." | ||
- ⏳ **Rate Limit Exceeded**: "Too many requests! Wait and try again." | ||
|
||
## Example | ||
|
||
```python | ||
try: | ||
app = easyai.create_app(name="example", service="openai") | ||
app.request("Test request") | ||
except Exception as e: | ||
print(e) | ||
``` |
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,25 @@ | ||
# Pipeline Guide | ||
|
||
## Overview | ||
Pipelines in EasyAI allow you to chain multiple tasks (e.g., text generation, image generation, and TTS) into a workflow. | ||
|
||
## Example Pipeline | ||
|
||
```python | ||
# Create a pipeline | ||
pipeline = easyai.EasyAIPipeline(app) | ||
|
||
# Add tasks | ||
pipeline.add_task("generate_text", "Write a poem about AI and nature.") | ||
pipeline.add_task("generate_image", "A futuristic city skyline.") | ||
pipeline.add_task("text_to_speech", "Here is a futuristic AI-powered city!") | ||
|
||
# Run the pipeline | ||
results = pipeline.run() | ||
|
||
# Print results | ||
for task_result in results: | ||
print(f"Task: {task_result['task']}\nResult: {task_result['result']}\n") | ||
``` | ||
|
||
Discover how to extend EasyAI with [Custom AI Models](./customai.md). |
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,33 @@ | ||
# Text-to-Speech Guide | ||
|
||
## Overview | ||
EasyAI supports OpenAI's Text-to-Speech API for converting text into audio files. | ||
|
||
## Generate Speech with OpenAI | ||
|
||
```python | ||
# Initialize a TTS App | ||
tts_app = easyai.create_tts_app( | ||
name="tts_app", | ||
service="openai", | ||
apikey="YOUR_API_KEY", | ||
model="tts-1" | ||
) | ||
|
||
# Convert text to speech | ||
output_file = tts_app.request_tts( | ||
text="Hello, I am your AI assistant!", | ||
tts_model="tts-1", | ||
voice="onyx", | ||
output_file="hello_ai.mp3" | ||
) | ||
|
||
print(f"TTS output saved to: {output_file}") | ||
``` | ||
|
||
## Supported Voices | ||
- `onyx` | ||
- `alloy` | ||
- `echo` | ||
|
||
Next, explore [Pipelines](./pipelines.md) for chaining tasks. |
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 |
---|---|---|
@@ -1,24 +1,39 @@ | ||
import anthropic | ||
|
||
from easilyai.exceptions import ( | ||
AuthenticationError, RateLimitError, InvalidRequestError, | ||
APIConnectionError, NotFoundError, ServerError, MissingAPIKeyError | ||
) | ||
|
||
class AnthropicService: | ||
def __init__(self, apikey, model, max_tokens = 1024): | ||
def __init__(self, apikey, model, max_tokens=1024): | ||
if not apikey: | ||
raise MissingAPIKeyError( | ||
"Anthropic API key is missing! Please provide your API key when initializing the service. " | ||
"Refer to the EasyAI documentation for more information." | ||
) | ||
self.apikey = apikey | ||
self.model = model | ||
self.max_tokens = max_tokens | ||
self.client = anthropic.Anthropic(apikey) | ||
self.client = anthropic.Anthropic(api_key=apikey) # Correct initialization | ||
|
||
def generate_text(self, prompt): | ||
try: | ||
response = self.client.messages.create(max_tokens = self.max_tokens, | ||
messages = [{"role": "user", "content": prompt}], | ||
model = self.model) | ||
return response.content | ||
response = self.client.messages.create( | ||
model=self.model, | ||
max_tokens=self.max_tokens, | ||
messages=[{"role": "user", "content": prompt}], | ||
) | ||
# Extract the text content | ||
return response.get("content")[0].get("text") | ||
except anthropic.errors.AuthenticationError: | ||
raise AuthenticationError("Invalid API key. Please check your Anthropic API key.") | ||
except anthropic.errors.RateLimitError: | ||
raise RateLimitError("Rate limit exceeded. Please wait and try again later.") | ||
except anthropic.errors.InvalidRequestError as e: | ||
raise InvalidRequestError(f"Invalid request: {str(e)}. Check your parameters.") | ||
except anthropic.errors.APIConnectionError: | ||
raise APIConnectionError("Unable to connect to Anthropic API. Check your network.") | ||
except Exception as e: | ||
raise ServerError( | ||
f"Unknown error occurred! Please try again later or look at the EasilyAi Docs. Error: {e}" | ||
f"An unexpected error occurred: {str(e)}. Please try again later." | ||
) |
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
Oops, something went wrong.