gptscript-ai / knowledge

Knowledge for GPTScript
https://gptscript-ai.github.io/knowledge/
Apache License 2.0
24 stars 11 forks source link

Should be able to use credential from `sys.openai` when used as remote tool #37

Closed sangee2004 closed 2 months ago

sangee2004 commented 3 months ago

Steps to reproduce the problem:

  1. Make sure OPENAI_API_KEY env is not set.
  2. Execute the following script that uses knowledge as remote tool - gptscript --workspace /Users/sangeethahariharan/k8sdoc/website/content/en/docs --debug knowledge_remote.gpt
    
    Tools: github.com/gptscript-ai/knowledge
    Context: github.com/gptscript-ai/context/workspace
    Chat: true

You are a helpful assistant that can retrieve information and answer questions using your tools. When you start just introduce yourself as Oracle and wait for the user to prompt you. You must use the knowledge tool to look up answers to your questions. Do NOT use the read tool. You may only answer questions with information you retrieve from the knowledge tool. Even if you've seen the question before and have the answer in your context, don't reuse the answer - go back to the knowledge tool because it's possible the information it gave you previously is out of date. When you give answers, always give a proper citation to the best of your abilities.


3. User will be prompted to enter openai token if `sys.openai` credential is not already present at which point `sys.openai` credential entry will be created.

4. When chatting with this script , we get the following error when files are being ingested - ```error response from the embedding API: 401 Unauthorized``` 
  {
    "role": "assistant",
    "content": "Hello, I am Oracle, your helpful assistant. How can I assist you today?"
  },
  {
    "role": "user",
    "content": "Give me details on pod eviction"
  },
  {
    "role": "assistant",
    "content": "",
    "tool_calls": [
      {
        "id": "call_sSQTEoYyq1MwftRJSUHE5PjP",
        "type": "function",
        "function": {
          "name": "knowledge",
          "arguments": "{\"query\":\"pod eviction\"}"
        }
      }
    ]
  },
  {
    "role": "tool",
    "content": "ERROR: got (exit status 1) while running tool, OUTPUT: 2024/06/27 15:54:35 INFO Created dataset id=default\n2024/06/27 15:54:35 INFO Created dataset id=46686c3b1fb4b4e1c6290d82a27a01136bc1b7bb\n2024/06/27 15:54:35 ERROR Failed to add documents error=\"couldn't add document 'b6b9d00e-ef00-4a3c-9338-5e16ba9d9d50': couldn't create embedding of document: error response from the embedding API: 401 Unauthorized\"\n2024/06/27 15:54:35 ERROR Failed to add documents error=\"couldn't add document '0329e9e0-a3c3-4ac7-9114-7782a9388130': couldn't create embedding of document: error response from the embedding API: 401 Unauthorized\"\n2024/06/27 15:54:35 ERROR Failed to add documents error=\"couldn't add document '63c20950-8455-4a80-b6b8-0cf3dbcae866': couldn't create embedding of document: error response from the embedding API: 401 Unauthorized\"\n2024/06/27 15:54:35 ERROR Failed to add documents error=\"couldn't add document 'b1c9a685-3c55-436f-8d4a-bd68ef787724': couldn't create embedding of document: error response from the embedding API: 401 Unauthorized\"\n2024/06/27 15:54:35 ERROR Failed to add documents error=\"couldn't add document '1792fe50-ba83-4963-817d-5cd6c587054f': couldn't create embedding of document: error response from the embedding API: 401 Unauthorized\"\n2024/06/27 15:54:36 ERROR Failed to add documents error=\"couldn't add document '706c0a9b-3985-4852-9e17-ac2b4c20b891': couldn't create embedding of document: error response from the embedding API: 401 Unauthorized\"\n2024/06/27 15:54:36 ERROR Failed to add documents error=\"couldn't add document '8a0288a2-7df8-4122-9015-3cf14d7b40ca': couldn't create embedding of document: error response from the embedding API: 401 Unauthorized\"\n2024/06/27 15:54:36 ERROR Failed to add documents error=\"couldn't add document 'a45c74bd-ddce-494e-861c-99bcd3351798': couldn't create embedding of document: error response from the embedding API: 401 Unauthorized\"\n2024/06/27 15:54:36 ERROR Failed to add documents error=\"couldn't add document 'c8f1e524-7610-4b20-96b4-db57dba18e11': couldn't create embedding of document: error response from the embedding API: 401 Unauthorized\"\n2024/06/27 15:54:36 ERROR Failed to add documents error=\"couldn't add document '24179edd-bec2-4ea7-9b4f-ab74c41b513e': couldn't create embedding of document: error response from the embedding API: 401 Unauthorized\"\n2024/06/27 15:54:36 failed to retrieve sources: failed to ingest files: failed to add documents: couldn't add document 'b6b9d00e-ef00-4a3c-9338-5e16ba9d9d50': couldn't create embedding of document: error response from the embedding API: 401 Unauthorized\n",
    "name": "knowledge",
    "tool_call_id": "call_sSQTEoYyq1MwftRJSUHE5PjP"
  },


**Expected Behavior:**
We should be able to use the credentials in `sys.openai` and should not have to rely on `OPENAI_API_KEY` to be present in this case.
iwilltry42 commented 2 months ago

Should be fixed now :+1: