-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
OPENAI_API_KEY= | ||
|
||
# Pinecone | ||
PINECONE_API_KEY= | ||
PINECONE_ENV= | ||
|
||
# search | ||
GOOGLE_API_KEY= | ||
GOOGLE_CX_ID= | ||
WOLFRAM_APP_ID= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import pytest | ||
|
||
from ix.commands.wolfram import search_wolfram | ||
|
||
|
||
class TestSearchWolfram: | ||
def test_search_wolfram_with_valid_query(self): | ||
query = "What is the capital of France?" | ||
results = search_wolfram(query) | ||
assert len(results) > 0 | ||
assert all(isinstance(result, tuple) for result in results) | ||
|
||
def test_search_wolfram_with_empty_query(self): | ||
query = "" | ||
with pytest.raises(ValueError): | ||
search_wolfram(query) | ||
|
||
def test_search_wolfram_with_missing_app_id(self, monkeypatch): | ||
monkeypatch.delenv("WOLFRAM_APP_ID", raising=False) | ||
query = "What is the capital of France?" | ||
with pytest.raises(ValueError): | ||
search_wolfram(query) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from typing import Callable, Any, List, Tuple | ||
import os | ||
import wolframalpha | ||
|
||
from ix.commands import command | ||
|
||
|
||
@command(name="search_wolfram", description="Search Wolfram.") | ||
def search_wolfram(search_string: str) -> List[Tuple[str, str]]: | ||
"""Searches Wolfram for the given search string and returns a list of (title, plaintext) tuples.""" | ||
app_id = os.environ.get("WOLFRAM_APP_ID") | ||
if not app_id: | ||
raise ValueError("WOLFRAM_APP_ID environment variable not set.") | ||
if not search_string: | ||
raise ValueError("search_string is required") | ||
client = wolframalpha.Client(app_id) | ||
print(search_string) | ||
res = client.query(search_string) | ||
results = [] | ||
for pod in res.pods: | ||
for subpod in pod.subpods: | ||
results.append((pod.title, subpod.plaintext)) | ||
return results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ ipython==8.12.0 | |
django_extensions==3.2.1 | ||
pinecone-client==2.2.1 | ||
tiktoken==0.3.3 | ||
wolframalpha==5.0.0 |