Inherited API-keys #230
-
Hello everybody, Here a code example:
The key is valid and it even generates an answer: The prompt_driver variable is already redundant as ToolkitTask should get the key from the pipeline (if no other is specified). Otherwise you would have to set the api key for each and every Task and tool it uses. Is there something that I overlook? Regards |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hey @urlmonitor! I just ran a slightly modified version of your example on griptape import os
from griptape.structures import Pipeline
from griptape.drivers import OpenAiChatPromptDriver
from griptape.tasks import ToolkitTask
from griptape.tools import WebScraper
openai_api_key = os.environ["OPENAI_API_KEY"]
llm_version = 'gpt-4'
pipeline = Pipeline(
prompt_driver=OpenAiChatPromptDriver(
temperature=0,
model=llm_version,
api_key=openai_api_key,
)
)
prompt_driver = OpenAiChatPromptDriver(
api_key=openai_api_key,
)
pipeline.add_tasks(
ToolkitTask(
"{{ args[0] }}. In case you want to use WebScraper, load the URL, and answer the users question.",
tools=[
WebScraper(),
],
prompt_driver=prompt_driver,
)
)
pipeline.run("Based on the website https://griptape.ai, tell me what griptape is.")
|
Beta Was this translation helpful? Give feedback.
-
It works for you as you have this os.environ["OPENAI_API_KEY"]. Try setting the key as a string and remove it from env. It works for me as well, when I dynamically set os.environ, but in a prod environment with multiple users this is probably not the best idea :D |
Beta Was this translation helpful? Give feedback.
@urlmonitor As of v0.17.0, you can now more easily specify an embedding driver that uses your API key: