langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
94.95k stars 15.38k forks source link

Add Alpha Vantage API Tool #11994

Closed adam-badar closed 8 months ago

adam-badar commented 1 year ago

Feature request

We propose the integration of a new tool into Langchain that will provide comprehensive support for queries on the AlphaVantage Trading API. AlphaVantage offers a wide range of financial data and services, and this integration will enhance Langchain's capabilities for financial data analysis.

Here is the list of AlphaVantage APIs that will be integrated into the new tool:

Motivation

The integration of AlphaVantage Trading API support in Langchain will provide users with access to a wealth of financial data, enabling them to perform in-depth analysis, develop trading strategies, and make informed financial decisions, all with real-time information

Your contribution

I am a University of Toronto Student, working in a group and plan to submit a PR for this issue in November

dosubot[bot] commented 1 year ago

🤖

Thank you for your interest in contributing to LangChain! We appreciate your proposal to integrate the AlphaVantage API tool into the framework. This addition will certainly enhance LangChain's capabilities for financial data analysis.

We encourage you to proceed with your plan to submit a pull request in November. Your contribution will be reviewed by the maintainers, who will assess its suitability for merging into the project.

If you have any questions or need assistance during the process, feel free to ask. Good luck with your contribution, and thank you for your support of LangChain!


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

aajaleel commented 1 year ago

@dosubot we updated the feature request, can you take a look again and provide any feedback?

devstein commented 1 year ago

@aajaleel As of now, Dosu only responds to the issue author 😄

Dosu isn't great at implementing features that require external docs yet, but try it out and see! It usually does a good job of finding reference classes within the codebase.

Let me know if you have feedback or ideas!

aajaleel commented 1 year ago

@devstein I was not aware, thank you for letting me know Devin! We'll definitely get started and check in with Dosu along the way. I'll keep you posted about how it goes, and please also share any suggestions you have as well!

adam-badar commented 11 months ago

@dosubot where in the repository can we find the current AlphaVantage Integration?

dosubot[bot] commented 11 months ago

🤖

The AlphaVantage Integration in the LangChain repository is located in the libs/langchain/langchain/utilities/alpha_vantage.py file. This file contains the AlphaVantageAPIWrapper class which is used to interact with the AlphaVantage API for Currency Exchange Rate.

The AlphaVantageAPIWrapper class includes methods for validating the API key, getting the exchange rate between two currencies, and running the exchange rate operation. The API key is stored in the ALPHAVANTAGE_API_KEY environment variable and is used in the _get_exchange_rate method to make a request to the AlphaVantage API.

Here is an example of how to use the AlphaVantageAPIWrapper class:

from langchain.utilities.alpha_vantage import AlphaVantageAPIWrapper

# Initialize the API wrapper
api_wrapper = AlphaVantageAPIWrapper()

# Get the exchange rate from USD to EUR
exchange_rate = api_wrapper.run("USD", "EUR")

print(f"The current exchange rate from USD to EUR is {exchange_rate}")

Please note that you need to have the ALPHAVANTAGE_API_KEY environment variable set for this to work, or you can pass the API key directly during the initialization of the AlphaVantageAPIWrapper class:

api_wrapper = AlphaVantageAPIWrapper(alphavantage_api_key="your_api_key_here")

You can find more details in the alpha_vantage.py file.

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

adam-badar commented 11 months ago

@dosu-bot We are trying to update the libs/langchain/langchain/utilities/alpha_vantage.py file. However we are getting the following error when running the file: ImportError: cannot import name 'timeout' from partially initialized module 'asyncio' (most likely due to a circular import).

Is there another way we can test our changes? What is the protocol for this?

dosubot[bot] commented 11 months ago

🤖

The error message you're encountering, ImportError: cannot import name 'timeout' from partially initialized module 'asyncio' (most likely due to a circular import), is typically due to a circular import issue in Python. This happens when two or more modules depend on each other, either directly or indirectly. In your case, it seems like the asyncio module is being imported in a way that causes this circular dependency.

To resolve this issue, you might want to refactor your code to avoid such dependencies. This could involve moving the import statements, changing the location of the import, or restructuring your code to remove the circular dependency.

As for testing your changes, the repository doesn't seem to have a specific testing protocol mentioned. However, a common practice in Python projects is to write unit tests for your code using a framework like unittest or pytest. These tests should cover all the functions in your code and should test for both expected and unexpected inputs.

For the alpha_vantage.py file, you might want to write tests for the validate_environment, _get_exchange_rate, and run functions. These tests should ensure that the functions behave as expected under different conditions. For example, you could test whether validate_environment correctly fetches the API key from the environment, whether _get_exchange_rate correctly fetches the exchange rate data and handles API errors, and whether run correctly gets the current exchange rate for a specified currency pair.

Once you've written your tests, you can run them using your chosen testing framework to ensure that your code works as expected. If all tests pass, you can be more confident that your changes haven't broken anything in the existing code.

Remember to also follow good software development practices, such as using version control, writing clear and concise commit messages, and documenting your code and changes.

I hope this helps! If you have any more questions or need further clarification, feel free to ask.

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.