Skip to content

Commit

Permalink
support azure openai interface in chatpaper function
Browse files Browse the repository at this point in the history
  • Loading branch information
张华仁 committed Jun 7, 2023
1 parent 659c043 commit 645ade1
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 19 deletions.
18 changes: 13 additions & 5 deletions apikey.ini
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
[OpenAI]
introductioon = the api key does not ''
OPENAI_API_KEYS = [your_key_0, ]
introduction = the api key does not ''
OPENAI_API_KEYS = [you_key_0, ]
CHATGPT_MODEL = gpt-3.5-turbo

[AzureOPenAI]
OPENAI_API_KEYS = ['']
OPENAI_API_BASE = ''
OPENAI_API_VERSION = ''
# Note, if you want to use the azure openai interface, you must configure the below parameters.
# The azure api-key
# Example: OPENAI_API_KEYS = 8c64572d63a54XXXXXa9345d624XXXXX
OPENAI_API_KEYS =
# The base URL for your Azure OpenAI resource. e.g. "https://<your resource name>.openai.azure.com"
OPENAI_API_BASE =
# Currently OPENAI API have the following versions available: 2023-03-15-preview, but this depends on your real environment.
OPENAI_API_VERSION =
# CHATGPT_MODEL
CHATGPT_MODEL =

[Gitee]
api = your_gitee_api
Expand Down
63 changes: 49 additions & 14 deletions chat_paper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class Paper:
def __init__(self, path, title='', url='', abs='', authers=[]):
# 初始化函数,根据pdf路径初始化Paper对象
self.url = url # 文章链接
self.url = url # 文章链接
self.path = path # pdf路径
self.section_names = [] # 段落标题
self.section_texts = {} # 段落内容
Expand Down Expand Up @@ -308,6 +308,17 @@ def __init__(self, key_word, query, filter_keys,

# prevent short strings from being incorrectly used as API keys.
self.chat_api_list = [api.strip() for api in self.chat_api_list if len(api) > 20]
self.chatgpt_model = self.config.get('OpenAI', 'CHATGPT_MODEL')

# 如果已经设置了OpenAI key, 则不使用Azure Interface
if not self.chat_api_list:
self.chat_api_list.append(self.config.get('AzureOPenAI', 'OPENAI_API_KEYS'))
self.chatgpt_model = self.config.get('AzureOPenAI', 'CHATGPT_MODEL')

openai.api_base = self.config.get('AzureOPenAI', 'OPENAI_API_BASE')
openai.api_type = 'azure'
openai.api_version = self.config.get('AzureOPenAI', 'OPENAI_API_VERSION')

self.cur_api = 0
self.file_format = args.file_format
if args.save_image:
Expand Down Expand Up @@ -585,11 +596,19 @@ def chat_conclusion(self, text, conclusion_prompt_token=800):
Be sure to use {} answers (proper nouns need to be marked in English), statements as concise and academic as possible, do not repeat the content of the previous <summary>, the value of the use of the original numbers, be sure to strictly follow the format, the corresponding content output to xxx, in accordance with \n line feed, ....... means fill in according to the actual requirements, if not, you can not write.
""".format(self.language, self.language)},
]
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
# prompt需要用英语替换,少占用token。
messages=messages,
)

if openai.api_type == 'azure':
response = openai.ChatCompletion.create(
engine=self.chatgpt_model,
# prompt需要用英语替换,少占用token。
messages=messages,
)
else:
response = openai.ChatCompletion.create(
model=self.chatgpt_model,
# prompt需要用英语替换,少占用token。
messages=messages,
)
result = ''
for choice in response.choices:
result += choice.message.content
Expand Down Expand Up @@ -633,10 +652,18 @@ def chat_method(self, text, method_prompt_token=800):
Be sure to use {} answers (proper nouns need to be marked in English), statements as concise and academic as possible, do not repeat the content of the previous <summary>, the value of the use of the original numbers, be sure to strictly follow the format, the corresponding content output to xxx, in accordance with \n line feed, ....... means fill in according to the actual requirements, if not, you can not write.
""".format(self.language, self.language)},
]
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages,
)
if openai.api_type == 'azure':
response = openai.ChatCompletion.create(
engine=self.chatgpt_model,
# prompt需要用英语替换,少占用token。
messages=messages,
)
else:
response = openai.ChatCompletion.create(
model=self.chatgpt_model,
# prompt需要用英语替换,少占用token。
messages=messages,
)
result = ''
for choice in response.choices:
result += choice.message.content
Expand Down Expand Up @@ -689,10 +716,18 @@ def chat_summary(self, text, summary_prompt_token=1100):
""".format(self.language, self.language, self.language)},
]

response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages,
)
if openai.api_type == 'azure':
response = openai.ChatCompletion.create(
engine=self.chatgpt_model,
# prompt需要用英语替换,少占用token。
messages=messages,
)
else:
response = openai.ChatCompletion.create(
model=self.chatgpt_model,
# prompt需要用英语替换,少占用token。
messages=messages,
)
result = ''
for choice in response.choices:
result += choice.message.content
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## Paper:1




1. Title: Good Robot!: Efficient Reinforcement Learning for Multi-Step Visual Tasks with Sim to Real Transfer

2. Authors: Andrew Hundt, Benjamin Killeen, Nicholas Greene, Hongtao Wu, Heeyeon Kwon, Chris Paxton, and Gregory D. Hager

3. Affiliation: The first author's affiliation: The Johns Hopkins University约翰·霍普金斯大学

4. Keywords: Reinforcement learning, sim to real transfer, multi-step tasks, computer vision, grasping and manipulation

5. Urls: Paper: None, Github code link: https://github.com/jhulcsr/good_robot

6. Summary:

- (1): 该文章的研究背景是复杂机器人任务的学习,这些任务具有多步骤和长周期性,学习这些任务对普通机器学习算法十分具有挑战性。

- (2): 过去的方法往往无法有效应对这些任务,如全盲搜索算法,可能探索到死马路;或者是朴素/非常规强化学习算法,容易反复强化错误的行为。因此,本文提出了一种基于“Positive Conditioning”原理并结合Sim to Real Transfer思想的SPOT框架,可以在安全的范围内进行探索,并在不探索不安全的区域的前提下有效学习和实现任务。

- (3): 本文提出的SPOT框架基于探索策略和奖励函数的设计,其核心思想着眼于贯彻安全有序性原则,以节约时间和取得令人满意的效果。具体方法至参看论文第三部分。

- (4): 本文中的方法在多种机器人任务上进行了模拟测试,结果非常成功,如堆叠4个方块的成功率从13%提高到100%;制作4行方块的成功率从13%提高到99%;以及对抗性地排布玩具的清理任务的成功率从84%提高到95%。此外,实验结果显示,该方法的行动效率通常可以提高30%或更多。最终他们提出的SPOT框架可以直接将模拟数据成功应用到真实环境中,取得不错的成果。
7. Methods:

- (1): 本文的核心思想是基于“Positive Conditioning”原理并结合Sim to Real Transfer思想的SPOT框架,其灵感来自于动物学习过程中的奖励机制,旨在在安全的范围内进行探索,并在不探索不安全的区域的前提下有效学习和实现多步骤和长周期性的机器人任务。

- (2): 本文使用马尔可夫决策过程作为系统模型,通过重塑奖励函数和设计探索策略的方法提高学习效率和安全性。具体方法包括Reward Shaping和SPOT-Q Learning以及动态操作空间等,其特点为保障安全有序性原则和减少无效尝试。

- (3): 本文方法的实验验证主要基于多种机器人视觉任务,包括堆叠方块、制作方块排列、对抗性地排放玩具等,结果显示该方法在学习成功率、效率和通用性方面较优,可以有效且直接地将模拟结果应用到真实机器人环境中。

- (4): 本文提出的SPOT框架的主要贡献是解决了复杂机器人任务学习的效率、安全性和通用性问题,同时结合了Sim to Real Transfer的思想,即可以在模拟环境中高效地训练,又可以有效地应用在真实环境中。





8. Conclusion:

- (1): 本文具有重要的实际意义,可以为长周期性机器人任务学习和实现带来有力的解决方案。该工作结合了“Positive Conditioning”原理和Sim to Real Transfer思想,提出了SPOT框架,能够有效保障安全有序性原则和提高学习效率和通用性,且可直接应用于真实机器人环境中。

- (2): 创新点:本文提出了基于SPOT框架的复杂机器人任务学习方法,其相比以前的方法具有安全性高、学习效率高和模拟结果与真实结果较为一致等优点。性能: 本文在多种机器人任务上进行了测试,验证了其学习效果和通用性。在对抗性地排放玩具的清理任务中,实现率可以高达95%;工作效率可以提高30%或更多。工作量: 本文中提出的方法和框架较为复杂,需要较高的技术水平和计算资源的支持,但是可以有效提高机器人任务的学习效率和安全性。




0 comments on commit 645ade1

Please sign in to comment.