Как вызвать модель Gemini Fine Trained (через Vertex AI) в Google ADK AgentPython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Как вызвать модель Gemini Fine Trained (через Vertex AI) в Google ADK Agent

Сообщение Anonymous »

Запись о проблеме : я настраивал модель Google Gemini Flash 2.0 через GCP Vertex AI. Но я не могу ссылаться на конечную точку той точно настроенной модели, обученной моим собственным данным в приведенном ниже агенте. Я предоставил весь код, который я имею ниже:-< /p>
Это мой агент.py < /p>
import os
from google.adk.agents import Agent
from google.adk.tools import google_search
from google.adk.tools.agent_tool import AgentTool
# from .fine_tune_llama3_8b import FineTuneLlama3 # Assuming this is in the same directory

# --- Set API Key ---
os.environ["GOOGLE_API_KEY"] = ""

# --- Root Agent ---
root_agent = Agent(
name="RootAgent",
model="gemini-2.0-flash-exp",
# model="gemini-2.0-flash-001"
description="AI Agent",
instruction=f"""
You are a helpful AI assistant.
""",
tools=[google_search]
)

# --- Root Agent for the Runner ---
from google.genai import types
from google.adk.sessions import InMemorySessionService
from google.adk.runners import Runner

# Instantiate constants
APP_NAME = "snack_creations_app"
USER_ID = "12345"
SESSION_ID = "123344"

# Session and Runner
session_service = InMemorySessionService()
session = session_service.create_session(
app_name=APP_NAME, user_id=USER_ID, session_id=SESSION_ID
)
runner = Runner(
agent=root_agent, app_name=APP_NAME, session_service=session_service
)

# Agent Interaction with Session for Context
def call_agent(query):
content = types.Content(role="user", parts=[types.Part(text=query)])
events = runner.run(user_id=USER_ID, session_id=SESSION_ID, new_message=content)

final_response = None
for event in events:
if event.is_final_response():
final_response = event.content.parts[0].text
print("Agent Response: ", final_response)
return final_response
return final_response

# Running Conversation
print("Starting the interactive conversation (type 'quit' to exit).")
while True:
user_query = input("You: ")
if user_query.lower() == 'quit':
break
call_agent(user_query)
print("\n")

print("Conversation ended.")
< /code>
Это мой штрафной код настроенной модели, заданный Vertex AI Post Fine-Model Model < /p>
from google import genai
from google.genai import types
import base64

def generate():
client = genai.Client(
vertexai=True,
project="9456734556734",
location="us-central1",
)

model = "projects/9456734556734/locations/us-central1/endpoints/5797762931831894471"
contents = [
types.Content(
role="user",
parts=[
types.Part.from_text(text="What is the maximum temperature used in the modulated DSC protocol ?")
]
)
]
generate_content_config = types.GenerateContentConfig(
temperature = 0.7,
top_p = 0.95,
max_output_tokens = 8192,
response_modalities = ["TEXT"],
speech_config = types.SpeechConfig(
voice_config = types.VoiceConfig(
prebuilt_voice_config = types.PrebuiltVoiceConfig(
voice_name = "zephyr"
)
),
),
safety_settings = [types.SafetySetting(
category="HARM_CATEGORY_HATE_SPEECH",
threshold="OFF"
),types.SafetySetting(
category="HARM_CATEGORY_DANGEROUS_CONTENT",
threshold="OFF"
),types.SafetySetting(
category="HARM_CATEGORY_SEXUALLY_EXPLICIT",
threshold="OFF"
),types.SafetySetting(
category="HARM_CATEGORY_HARASSMENT",
threshold="OFF"
)],
)

for chunk in client.models.generate_content_stream(
model = model,
contents = contents,
config = generate_content_config,
):
print(chunk.text, end="")

generate()
< /code>
Я попытался вывести свою тонкую конечную точку модели в агент, но это не работает. Есть ли способ использовать свою модель в Agent.py? Я не уверен, было ли это реализовано Google или нет. Любая помощь будет оценена.

Подробнее здесь: https://stackoverflow.com/questions/796 ... -adk-agent
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»