Forum in maintenance, we will back soon 🙂
@sonu-choudhary but your code has a space in the URL that doesn't belong when you are using curl to make a call to the API.
Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack
@admin sure im creating a streamlit apps using google gemini api but im stuck at wordpress what code you want ..?
import os import textwrap from IPython.display import display from IPython.display import Markdown import streamlit as st import google.generativeai as genai from dotenv import load_dotenv load_dotenv() # take environment variables from .env. # Initialize Gemini-Pro genai.configure(api_key=os.getenv("GOOGLE_GEMINI_KEY")) model = genai.GenerativeModel('gemini-pro') # Gemini uses 'model' for assistant; Streamlit uses 'assistant' def role_to_streamlit(role): if role == "model": return "assistant" else: return role # Add a Gemini Chat history object to Streamlit session state if "chat" not in st.session_state: st.session_state.chat = model.start_chat(history = []) # Display Form Title st.title("Chat with Google Gemini-Pro!") # Display chat messages from history above current input box for message in st.session_state.chat.history: with st.chat_message(role_to_streamlit(message.role)): st.markdown(message.parts[0].text) # Accept user's next message, add to context, resubmit context to Gemini if prompt := st.chat_input("I possess a well of knowledge. What would you like to know?"): # Display user's last message st.chat_message("user").markdown(prompt) # Send user entry to Gemini and read the response response = st.session_state.chat.send_message(prompt) # Display last with st.chat_message("assistant"): st.markdown(response.text)
@sonu-choudhary I would suggest getting rid of the IPython imports. I don't see that you use these in the code.
Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack
@sonu-choudhary Thank you, I will work on a WordPress code for this week
@admin yes please share WordPress code im Waiting for ur Blog or Video about it
function gemini_generate_text() { $topic = $_POST['topic']; $prompt = "Generate 5 youtube titles for a video about " . $topic; $api_key = 'AIzaSyDw4xb0'; $api_url = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=' . $api_key ; // Headers for the Gemini API $headers = [ 'Content-Type' => 'application/json' ]; // Body for the Gemini API $body = [ 'contents' => [ [ 'parts' => [ ['text' => $prompt] ] ] ] ]; // Args for the WordPress HTTP API $args = [ 'method' => 'POST', 'headers' => $headers, 'body' => json_encode($body), 'timeout' => 120 ]; // Send the request $response = wp_remote_request($api_url, $args); wp_send_json_success($response); // Always die in functions echoing AJAX content wp_die(); } add_action('wp_ajax_gemini_generate_text', 'gemini_generate_text'); add_action('wp_ajax_nopriv_gemini_generate_text', 'gemini_generate_text');
here is a sample working example
Â
@admin okk and as per your create ai tools in 5 minutes in wp blog other code is same right html and js one ...?
@admin or can you create one more blog about this how create tool step by step its being helpful for us
@sonu-choudhary this code is a generic function to call the gemeni APi and get a response, it is not exactly the same as the openAI code. you need to tweek a little bit to fit your needs. I will try to create a tutorial about it
@sonu-choudhary Sorry, friend, I can't promise to do it quickly. I will add it to my schedule.