Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请教一下,openai账号和key单独测试可用,已经设置OPENAI_API_KEY,但是程序一直提示链接不上OPENAI #3

Closed
ahong007007 opened this issue Jul 28, 2023 · 6 comments

Comments

@ahong007007
Copy link

image

@EthanC111
Copy link
Collaborator

EthanC111 commented Jul 28, 2023

@ahong007007 感謝你的提問!
OpenAI API會擋 中國大陸的 request. 一般來說 就算有vpn 可能也未必能用 可以試試以下的 snippet 看能不能跑.
如果不行的話 代表應該是openai的問題 最好使用AWS 或者比較小眾的vpn (太大眾的一般來說會被openai ban掉).
如果以下的snippet可以跑 那代表是其他問題 那再請讓我知道!
let me know if you have more questions!

import openai

messages =  [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello!"}]

response = openai.ChatCompletion.create(model='gpt-3.5-turbo', messages=messages, max_tokens=2000, temperature=0.5)

print(response)

@ahong007007
Copy link
Author

您好,感谢您的回复。
设置VPN后可以跑起来了,但是遇到新的问题,

由于VPN限制,在个人电脑运行,出现
concurrent.futures.process.BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.

请问是电脑配置过低导致的问题?如何修改?

image

@EthanC111
Copy link
Collaborator

EthanC111 commented Jul 28, 2023

我在stackoverflow看到這個:
https://stackoverflow.com/questions/15900366/all-example-concurrent-futures-code-is-failing-with-brokenprocesspool

可能要把example.py改成:

from factool import Factool

factool_instance = Factool("gpt-4")

# one example input for each category.
inputs = [
            {
                "prompt": "Introduce Graham Neubig",
                "response": "Graham Neubig is a professor at MIT",
                "category": "kbqa"
            },
            {
                "prompt": "def get_max_triples(n): \"\"\" You are given a positive integer n. You have to create an integer array a of length n. For each i (1 \u2264 i \u2264 n), the value of a[i] = i * i - i + 1. Return the number of triples (a[i], a[j], a[k]) of a where i < j < k, and a[i] + a[j] + a[k] is a multiple of 3. Example : Input: n = 5 Output: 1 Explanation: a = [1, 3, 7, 13, 21] The only valid triple is (1, 7, 13). \"\"\" Now implement the function get_max_triples using Python",
                "response": "def get_max_triples(n):\n    a = [i * i - i + 1 for i in range(1, n+1)]\n    count = 0\n    for i in range(n-2):\n        for j in range(i+1, n-1):\n            for k in range(j+1, n):\n                if (a[i] + a[j] + a[k]) % 3 == 0:\n                    count += 1\n    return count\n\nprint(get_max_triples(5)) # Output: 1",
                "category": "code",
                "entry_point": "get_max_triples"
            },
            {
                "prompt": "Stephen placed an online order for groceries.  His final bill came to $7023116.  Because this was through a delivery vendor, they tacked on a 25% fee to his final total and charged him $3.00 in delivery fees.  Stephen also added a $4.00 tip.  After the extra fees, what was the final price of Stephen's groceries?",
                "response": "Okay, here are the steps to solve this:\n* Stephen's initial grocery bill was $7023116\n* The delivery vendor charged a 25% fee on top of that. 25% of $7023116 is 0.25 * $7023116 = $1755779\n* They also charged a flat $3 delivery fee\n* Stephen added a $4 tip\n* So the total charges were:\n    * Initial groceries: $7023116\n    * 25% fee: $1755779\n    * Delivery fee: $3 \n    * Tip: $4\n* Adding all that up, the total final price was $7023116 + $1755779 + $3 + $4 = $8779902\n\nSo the final price of Stephen's groceries was $8779902",
                "category": "math"
            },
            {
                "prompt": "Detail how machine learning algorithms are applied in data"
                      " analytics and the processes involved in training"
                      " these algorithms. Please cite relevant research papers"
                      " or textbooks to support your points, including the author's"
                      " name, the title of the work, and the year of publication.",
                "response": "Machine learning algorithms play a crucial role in data"
                        " analytics. They are used to extract insights and knowledge"
                        " from large datasets, which can be used to make informed"
                        " decisions and predictions. The following are the processes"
                        " involved in training machine learning algorithms:\n\n1. "
                        "Data Preprocessing: The first step in training a machine"
                        " learning algorithm is to preprocess the data. This involves"
                        " cleaning the data, handling missing values, "
                        "encoding categorical variables, and scaling the data. "
                        "The aim of preprocessing is to ensure that the data is in"
                        " a format that can be used by the machine learning algorithm.\n2. Feature Selection: Once the data has been preprocessed, the next step is to select the relevant features that will be used to train the machine learning algorithm. This involves identifying the features that are most important for predicting the target variable. Feature selection can be done using various techniques, such as filter methods, wrapper methods, and embedded methods.\n3. Model Selection: After feature selection, the next step is to select the appropriate machine learning algorithm to use. There are various types of machine learning algorithms, such as supervised learning, unsupervised learning, and reinforcement learning. The choice of algorithm depends on the nature of the problem and the type of data available.\n4. Training the Model: Once the model has been selected, the next step is to train the machine learning algorithm using the preprocessed data. This involves using a training set of data to optimize the parameters of the model so that it can accurately predict the target variable.\n5. Model Evaluation: After the model has been trained, the next step is to evaluate its performance. This involves testing the model on a separate test set of data and measuring its accuracy, precision, recall, and other performance metrics.\n6. Model Deployment: Once the model has been evaluated and fine-tuned, it can be deployed in a production environment. This involves integrating the model into a larger system or workflow, and monitoring its performance over time.\n\nResearch papers and textbooks that support the above points include:\n\n* \"An Introduction to Machine Learning\" by Alpaydin, B., (2010) which provides a comprehensive overview of machine learning algorithms and their applications.\n* \"Data Mining: Concepts and Techniques\" by Han, J., Kamber, B., & Pei, J., (2011) which provides a detailed introduction to data mining and its applications.\n* \"Machine Learning: Trends, Perspectives, and Prospects\" by Kamber, B., & Pei, J., (2012) which provides an overview of the current trends and future prospects of machine learning.\n* \"Machine Learning for Data Mining\" by He, C., & Wang, Y., (2015) which provides an in-depth introduction to machine learning algorithms and their applications in data mining.",
                "category": "scientific"
            }
]

if __name__ == '__main__':
    response_list = factool_instance.run(inputs)

print(response_list)

如果不行再跟我說! 謝謝!

@ahong007007
Copy link
Author

感谢您的回复,貌似又出现新的问题,😰
example只运行code部分,

from factool import Factool
import openai

proxies = {'http': "http://127.0.0.1:7078",
           'https': "http://127.0.0.1:7078"}
openai.proxy = proxies


factool_instance = Factool("gpt-3.5-turbo")

# one example input for each category.
inputs = [
    {
        "prompt": "def get_max_triples(n): \"\"\" You are given a positive integer n. You have to create an integer array a of length n. For each i (1 \u2264 i \u2264 n), the value of a[i] = i * i - i + 1. Return the number of triples (a[i], a[j], a[k]) of a where i < j < k, and a[i] + a[j] + a[k] is a multiple of 3. Example : Input: n = 5 Output: 1 Explanation: a = [1, 3, 7, 13, 21] The only valid triple is (1, 7, 13). \"\"\" Now implement the function get_max_triples using Python",
        "response": "def get_max_triples(n):\n    a = [i * i - i + 1 for i in range(1, n+1)]\n    count = 0\n    for i in range(n-2):\n        for j in range(i+1, n-1):\n            for k in range(j+1, n):\n                if (a[i] + a[j] + a[k]) % 3 == 0:\n                    count += 1\n    return count\n\nprint(get_max_triples(5)) # Output: 1",
        "category": "code",
        "entry_point": "get_max_triples"
    }
]
if __name__ == '__main__':
    response_list = factool_instance.run(inputs)
    print(response_list)


AttributeError: Can't pickle local object 'test_case_against_solution..unsafe_execute'

image

@EthanC111
Copy link
Collaborator

EthanC111 commented Jul 28, 2023

可能跟這個有關https://stackoverflow.com/questions/72766345/attributeerror-cant-pickle-local-object-in-multiprocessing

可能可以試一下改 ./factool/code/helper/_execution.py, 把 import multiprocessing 改成 import multiprocess as mp (記得pip install multiprocess),然後下面的 manager = multiprocessing.Manager() 改成 manager = mp.Manager(),然後p = multiprocessing.Process(target=unsafe_execute)改成p = mp.Process(target=unsafe_execute)

然後安裝就從Source重新安裝 pip install -e .

如果有問題可以在留言!

@ahong007007
Copy link
Author

您好,感谢您的耐心回复 @EthanC111 我迁移到linux环境,已经可以正常运行。

您有微信,推特或者其他聊天工具吗,关于论文,还有想法和您交流一下,^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants