Anthropic AI models support

This commit is contained in:
ajaysi
2024-06-29 10:04:19 +05:30
parent 591c373aef
commit 60f0bbaa07
4 changed files with 51 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
# How to Alwrity - Getting Started # How to Alwrity - Getting Started
Alwrity assists content creators and digital marketers in keyword web research, AI website & Social media content generation & AI Copywriting. Alwrity assists content creators and digital marketers in keyword web research, AI website & Social media content generation & AI Copywriting.
Our toolkit integrates (OpenAI, Gemini) AI models for text generation, image creation(Stability.ai), STT(whisper, AssemblyAI) and Web or local data analysis, streamlining your content creation pipeline and ensuring high-quality output with minimal effort. Our toolkit integrates (OpenAI, Gemini, Anthropic) AI models for text generation, image creation(Stability.ai), STT(whisper, AssemblyAI) and Web or local data analysis, streamlining your content creation pipeline and ensuring high-quality output with minimal effort.
Prompting is abstracted to get going sooner. Focus on your content quality, rather than AI tooling around it. Prompting is abstracted to get going sooner. Focus on your content quality, rather than AI tooling around it.
Alwrity gives personalization, factual web researched & SEO optimized content and tools for automating content & digital marketing. Alwrity gives personalization, factual web researched & SEO optimized content and tools for automating content & digital marketing.
@@ -58,8 +58,11 @@ If you have 💻 Laptop + 🛜 Internet + 10 minutes, you will be generating blo
| 14 | Agentic Content Creation | Explores innovative content creation methods with CrewAI. | | 14 | Agentic Content Creation | Explores innovative content creation methods with CrewAI. |
| 15 | AI Finance Writer | Uses ufinance & padnas_ta to write TA report for given stock symbol | | 15 | AI Finance Writer | Uses ufinance & padnas_ta to write TA report for given stock symbol |
| 16 | AI Agents Team | Easily create AI Agents team for Content creation & Digital marketing | | 16 | AI Agents Team | Easily create AI Agents team for Content creation & Digital marketing |
| 17 | Talk to your Docs | Write content from your local documents of any type(multi-modal) | | 17 | Talk to your Docs (WIP) | Write content from your local documents of any type(multi-modal) |
| 18 | Wordpress API integration | Programmatically upload blogs to wordpress website with API keys | | 18 | Wordpress API integration | Programmatically upload blogs to wordpress website with API keys |
| 19 | Talk to your website | Crawl Crawl your entire website & write content based on its content, Or Not |
| 20 | Content From URLs | Provide any URL to create an original, unique content from |
--- ---
# AI Content Generation Toolkit - Alwrity # AI Content Generation Toolkit - Alwrity

View File

@@ -0,0 +1,33 @@
import os
import anthropic
from anthropic import Anthropic
import streamlit as st
def anthropic_text_response(prompt):
""" """
client = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"),)
try:
response = client.messages.create(
max_tokens=1024,
messages=[
{
"role": "user",
"content": prompt,
}
],
# This will come from config file.
model="claude-3-opus-20240229",
)
return(message.content)
except anthropic.APIConnectionError as e:
st.error("The server could not be reached")
st.error(e.__cause__) # an underlying Exception, likely raised within httpx.
except anthropic.RateLimitError as e:
st.error("A 429 status code was received; we should back off a bit.")
except anthropic.APIStatusError as e:
st.error("Another non-200-range status code was received")
st.error(e.status_code)
st.error(e.response)

View File

@@ -14,6 +14,7 @@ logger.add(sys.stdout,
from .openai_text_gen import openai_chatgpt from .openai_text_gen import openai_chatgpt
from .gemini_pro_text import gemini_text_response from .gemini_pro_text import gemini_text_response
from .anthropic_text_gen import anthropic_text_response
from ...utils.read_main_config_params import read_return_config_section from ...utils.read_main_config_params import read_return_config_section
@@ -49,6 +50,14 @@ def llm_text_gen(prompt):
except Exception as err: except Exception as err:
logger.error(f"Failed to get response from Openai: {err}") logger.error(f"Failed to get response from Openai: {err}")
raise err raise err
elif 'anthropic' in gpt_provider.lower():
try:
logger.info(f"Using Anthropic Model: {model} for text Generation.")
response = anthropic_text_response(prompt)
return response
except Exception as err:
logger.error(f"Failed to get response from Anthropic: {err}")
raise err
except Exception as err: except Exception as err:
logger.error(f"Failed to read LLM parameters: {err}") logger.error(f"Failed to read LLM parameters: {err}")
@@ -95,6 +104,8 @@ def get_api_key(gpt_provider):
api_key = os.getenv('GEMINI_API_KEY') api_key = os.getenv('GEMINI_API_KEY')
elif gpt_provider.lower() == 'openai': elif gpt_provider.lower() == 'openai':
api_key = os.getenv('OPENAI_API_KEY') api_key = os.getenv('OPENAI_API_KEY')
elif gpt_provider.lower() == 'anthropic':
api_key = os.getenv('ANTHROPIC_API_KEY')
if not api_key: if not api_key:
raise ValueError(f"No API key found for the specified GPT provider: '{gpt_provider}'") raise ValueError(f"No API key found for the specified GPT provider: '{gpt_provider}'")

View File

@@ -9,7 +9,7 @@ crewai_tools
python-docx python-docx
PyPDF2 PyPDF2
google.generativeai google.generativeai
mistralai anthropic
tenacity tenacity
tavily-python tavily-python
tabulate tabulate
@@ -35,3 +35,4 @@ pandas_ta
firecrawl-py firecrawl-py
gTTS gTTS
streamlit-mic-recorder streamlit-mic-recorder