forked from InternLM/MindSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull Request: Integrate .env File Support and Add Backend Usage Examp…
…le (InternLM#187) * feat: Integrate .env file support for environment variables feat: Add backend_example.py file support for using without a frontend - Added .env.example with necessary environment variable placeholders: OPENAI_API_KEY, OPENAI_API_BASE, OPENAI_MODEL, SILICON_API_KEY, SILICON_MODEL. - Updated models.py to load environment variables using python-dotenv. - Modified gpt4 amd silicon model configurations to use values from .env file or defaults. - Updated .gitignore to exclude .env file. - Updated requirements.txt to include python-dotenv. - Updated README.md to document environment variable setup and backend usage example. - Added backend_example.py for direct backend interaction. * (README.md): remove new features section from forked version
- Loading branch information
1 parent
4bd0e24
commit 98fd84d
Showing
6 changed files
with
87 additions
and
27 deletions.
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,5 @@ | ||
OPENAI_API_KEY= | ||
OPENAI_API_BASE= | ||
OPENAI_MODEL= | ||
SILICON_API_KEY= | ||
SILICON_MODEL= |
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
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,34 @@ | ||
import json | ||
import requests | ||
|
||
# Define the backend URL | ||
url = 'http://localhost:8002/solve' | ||
headers = {'Content-Type': 'application/json'} | ||
|
||
# Function to send a query to the backend and get the response | ||
def get_response(query): | ||
# Prepare the input data | ||
data = {'inputs': [{'role': 'user', 'content': query}]} | ||
|
||
# Send the request to the backend | ||
response = requests.post(url, headers=headers, data=json.dumps(data), timeout=20, stream=True) | ||
|
||
# Process the streaming response | ||
for chunk in response.iter_lines(chunk_size=8192, decode_unicode=False, delimiter=b'\n'): | ||
if chunk: | ||
decoded = chunk.decode('utf-8') | ||
if decoded == '\r': | ||
continue | ||
if decoded[:6] == 'data: ': | ||
decoded = decoded[6:] | ||
elif decoded.startswith(': ping - '): | ||
continue | ||
response_data = json.loads(decoded) | ||
agent_return = response_data['response'] | ||
node_name = response_data['current_node'] | ||
print(f"Node: {node_name}, Response: {agent_return['response']}") | ||
|
||
# Example usage | ||
if __name__ == '__main__': | ||
query = "What is the weather like today in New York?" | ||
get_response(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
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 |
---|---|---|
|
@@ -10,3 +10,4 @@ sse-starlette | |
termcolor | ||
transformers==4.41.0 | ||
uvicorn | ||
python-dotenv |