Skip to content

Instantly share code, notes, and snippets.

@rajivmehtaflex
Created June 26, 2024 14:52
Show Gist options
  • Save rajivmehtaflex/46d668fa15a7bf057435563fb5d95ec6 to your computer and use it in GitHub Desktop.
Save rajivmehtaflex/46d668fa15a7bf057435563fb5d95ec6 to your computer and use it in GitHub Desktop.
Abacus AI References.
give me hello-world style code for call language model for gpt-4o.I'm talking about evaluate_prompt base example
User Icon
To call a language model for GPT-4O using the evaluate_prompt method, you can use the following example code in Python:
from abacusai import ApiClient
# Initialize the API client with your API key
client = ApiClient(api_key='YOUR_API_KEY')
# Define the prompt and other parameters
prompt = "Hello, world!"
system_message = "Respond with a greeting"
llm_name = "OPENAI_GPT4O"
max_tokens = 20
temperature = 0.1
# Call the evaluate_prompt method
response = client.evaluate_prompt(
prompt=prompt,
system_message=system_message,
llm_name=llm_name,
max_tokens=max_tokens,
temperature=temperature
)
# Print the response
print(response.content)
Replace 'YOUR_API_KEY' with your actual API key. This code initializes the API client, sets the parameters for the prompt, and calls the evaluate_prompt method to get a response from the GPT-4O model. The response content is then printed.
I want to analyze image for OPENAI_GPT4_VISION as llm_name ,give me example of this
User Icon
To analyze an image using the OPENAI_GPT4_VISION model as the llm_name, you can use the following example code in Python:
from abacusai import ApiClient
# Initialize the API client with your API key
client = ApiClient(api_key='YOUR_API_KEY')
# Define the image file path and other parameters
image_path = 'path/to/your/image.jpg'
system_message = "Analyze the image and describe its content"
llm_name = "OPENAI_GPT4_VISION"
max_tokens = 100
temperature = 0.5
# Read the image file
with open(image_path, 'rb') as image_file:
image_data = image_file.read()
# Call the evaluate_prompt method with the image data
response = client.evaluate_prompt(
prompt=image_data,
system_message=system_message,
llm_name=llm_name,
max_tokens=max_tokens,
temperature=temperature
)
# Print the response
print(response.content)
Replace 'YOUR_API_KEY' with your actual API key and 'path/to/your/image.jpg' with the path to the image you want to analyze. This code initializes the API client, reads the image file, sets the parameters for the prompt, and calls the evaluate_prompt method to get a response from the OPENAI_GPT4_VISION model. The response content is then printed.
what is constant for claude sonnet 3.5 so that I can use in evaluate_prompt function with llm_name parameter?
User Icon
The constant for Claude Sonnet 3.5 that you can use in the evaluate_prompt function with the llm_name parameter is "CLAUDE_V3_SONNET".
Here is an example of how you can use it in the evaluate_prompt function:
from abacusai import ApiClient
# Initialize the API client with your API key
client = ApiClient(api_key='YOUR_API_KEY')
# Define the prompt and other parameters
prompt = "Write a sonnet about the beauty of nature."
system_message = "Respond with a sonnet"
llm_name = "CLAUDE_V3_SONNET"
max_tokens = 100
temperature = 0.7
# Call the evaluate_prompt method
response = client.evaluate_prompt(
prompt=prompt,
system_message=system_message,
llm_name=llm_name,
max_tokens=max_tokens,
temperature=temperature
)
# Print the response
print(response.content)
Replace 'YOUR_API_KEY' with your actual API key. This code initializes the API client, sets the parameters for the prompt, and calls the evaluate_prompt method to get a response from the CLAUDE_V3_SONNET model. The response content is then printed.
How can i generate image using CLAUDE_V3_SONNET ,can you give me example for it?
User Icon
The CLAUDE_V3_SONNET model is designed for text generation, specifically for generating sonnets and other text-based outputs. It does not support image generation. If you want to generate images, you would need to use a model that is specifically designed for image generation, such as DALL-E or other similar models.
Since CLAUDE_V3_SONNET is not capable of generating images, I cannot provide an example for image generation using this model. If you have any other questions or need examples for text generation using CLAUDE_V3_SONNET, feel free to ask!
can you give me example of function calling i.e. for OPENAI_GPT4O as llm_name ,I want to use with evaluate_prompt
User Icon
To call a function using the OPENAI_GPT4O model as the llm_name with the evaluate_prompt method, you can use the following example code in Python:
from abacusai import ApiClient
# Initialize the API client with your API key
client = ApiClient(api_key='YOUR_API_KEY')
# Define the prompt and other parameters
prompt = "Calculate the sum of 5 and 3."
system_message = "Respond with the result of the calculation"
llm_name = "OPENAI_GPT4O"
max_tokens = 20
temperature = 0.1
# Call the evaluate_prompt method
response = client.evaluate_prompt(
prompt=prompt,
system_message=system_message,
llm_name=llm_name,
max_tokens=max_tokens,
temperature=temperature
)
# Print the response
print(response.content)
Replace 'YOUR_API_KEY' with your actual API key. This code initializes the API client, sets the parameters for the prompt, and calls the evaluate_prompt method to get a response from the OPENAI_GPT4O model. The response content is then printed.
In this example, the prompt asks the model to calculate the sum of 5 and 3, and the system message instructs the model to respond with the result of the calculation. The evaluate_prompt method is used to get the response from the OPENAI_GPT4O model.
how can i use with langchain,give me example for it.
User Icon
To use the evaluate_prompt method with LangChain and the OPENAI_GPT4O model, you can integrate the Abacus.AI API within a LangChain pipeline. Below is an example of how you can achieve this in Python:
Install LangChain: If you haven't already, you need to install LangChain. You can do this using pip:
pip install langchain
Integrate Abacus.AI with LangChain: Below is an example code that demonstrates how to use the evaluate_prompt method from Abacus.AI within a LangChain pipeline.
from langchain import LLMChain, PromptTemplate
from abacusai import ApiClient
# Initialize the API client with your API key
client = ApiClient(api_key='YOUR_API_KEY')
# Define a function to call the evaluate_prompt method
def call_openai_gpt4o(prompt, system_message, max_tokens=20, temperature=0.1):
response = client.evaluate_prompt(
prompt=prompt,
system_message=system_message,
llm_name="OPENAI_GPT4O",
max_tokens=max_tokens,
temperature=temperature
)
return response.content
# Define a prompt template
template = PromptTemplate(
input_variables=["input_text"],
template="Calculate the sum of 5 and 3. {input_text}"
)
# Define a custom LLMChain that uses the Abacus.AI API
class AbacusLLMChain(LLMChain):
def __init__(self, prompt_template):
super().__init__(prompt_template)
def _call(self, inputs):
prompt = self.prompt_template.format(**inputs)
system_message = "Respond with the result of the calculation"
return call_openai_gpt4o(prompt, system_message)
# Create an instance of the custom LLMChain
abacus_chain = AbacusLLMChain(prompt_template=template)
# Use the chain to generate a response
input_text = ""
response = abacus_chain.run(input_text=input_text)
# Print the response
print(response)
Explanation:
Initialize the API Client: The ApiClient is initialized with your API key.
Define the Function: The call_openai_gpt4o function calls the evaluate_prompt method from Abacus.AI.
Prompt Template: A PromptTemplate is defined to structure the input prompt.
Custom LLMChain: A custom LLMChain class (AbacusLLMChain) is created to use the Abacus.AI API.
Generate Response: An instance of the custom LLMChain is created and used to generate a response.
Replace 'YOUR_API_KEY' with your actual API key and adjust the prompt and system message as needed. This code integrates the Abacus.AI API within a LangChain pipeline, allowing you to use the evaluate_prompt method with the OPENAI_GPT4O model.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment