fix:两个数组的交集

上级 b26175ca
2023-06-25 11:27:36 - WARNING! engine is not default parameter.
engine was transferred to model_kwargs.
Please confirm that engine is what you intended.
2023-06-25 11:27:36 - Your app is available at http://localhost:8000
...@@ -2,11 +2,10 @@ import os ...@@ -2,11 +2,10 @@ import os
from langchain import PromptTemplate, OpenAI, LLMChain from langchain import PromptTemplate, OpenAI, LLMChain
import chainlit as cl import chainlit as cl
# os.environ["OPENAI_API_KEY"] = "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" os.environ["http_proxy"] = "http://localhost:7890"
os.environ["OPENAI_API_KEY"] = "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" os.environ["https_proxy"] = "http://localhost:7890"
os.environ["OPENAI_API_KEY"] = "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"
template = """Question: {question} template = """Question: {question}
Answer: Let's think step by step.""" Answer: Let's think step by step."""
...@@ -14,5 +13,4 @@ Answer: Let's think step by step.""" ...@@ -14,5 +13,4 @@ Answer: Let's think step by step."""
def factory(): def factory():
prompt = PromptTemplate(template=template, input_variables=["question"]) prompt = PromptTemplate(template=template, input_variables=["question"])
llm_chain = LLMChain(prompt=prompt, llm=OpenAI(temperature=0), verbose=True) llm_chain = LLMChain(prompt=prompt, llm=OpenAI(temperature=0), verbose=True)
return llm_chain return llm_chain
import openai import openai
import chainlit as cl import chainlit as cl
openai.api_key = "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" openai.proxy = 'http://127.0.0.1:7890'
# 道英
# openai.api_key = "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"
# 我的key
openai.api_key = "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"
# model_name = "text-davinci-003" # model_name = "text-davinci-003"
model_name = "gpt-3.5-turbo" model_name = "gpt-3.5-turbo"
settings = { settings = {
...@@ -25,14 +30,11 @@ def start_chat(): ...@@ -25,14 +30,11 @@ def start_chat():
async def main(message: str): async def main(message: str):
message_history = cl.user_session.get("message_history") message_history = cl.user_session.get("message_history")
message_history.append({"role": "user", "content": message}) message_history.append({"role": "user", "content": message})
msg = cl.Message(content="") msg = cl.Message(content="")
async for stream_resp in await openai.ChatCompletion.acreate( async for stream_resp in await openai.ChatCompletion.acreate(
model=model_name, messages=message_history, stream=True, **settings model=model_name, messages=message_history, stream=True, **settings
): ):
token = stream_resp.choices[0]["delta"].get("content", "") token = stream_resp.choices[0]["delta"].get("content", "")
await msg.stream_token(token) await msg.stream_token(token)
message_history.append({"role": "assistant", "content": msg.content}) message_history.append({"role": "assistant", "content": msg.content})
await msg.send() await msg.send()
import openai import openai
import chainlit as cl import chainlit as cl
openai.proxy = 'http://127.0.0.1:7890'
openai.api_key = "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" openai.api_key = "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"
model_name = "text-davinci-003" model_name = "text-davinci-003"
settings = { settings = {
...@@ -11,6 +13,7 @@ settings = { ...@@ -11,6 +13,7 @@ settings = {
"presence_penalty": 0, "presence_penalty": 0,
"stop": ["```"], "stop": ["```"],
} }
prompt = """Answer the following question: prompt = """Answer the following question:
{question} {question}
""" """
......
"""
两个数组的交集
给定两个数组 nums1 和 nums2 ,返回 它们的交集 。输出结果中的每个元素一定是 唯一 的。我们可以 不考虑输出结果的顺序 。
"""
from typing import List
class Solution:
def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
return list(set(nums1).intersection(nums2))
if __name__ == '__main__':
result = Solution().intersection([1, 2, 2, 1], [2, 2])
print(result)
"""
两个数组的交集
给定两个数组 nums1 和 nums2 ,返回 它们的交集 。输出结果中的每个元素一定是 唯一 的。我们可以 不考虑输出结果的顺序 。
"""
from typing import List
class Solution:
def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
list1 = set(nums1)
list2 = set(nums2)
return list(list1 & list2)
if __name__ == '__main__':
result = Solution().intersection([1, 2, 2, 1], [2, 2])
print(result)
"""
两个数组的交集
给定两个数组 nums1 和 nums2 ,返回 它们的交集 。输出结果中的每个元素一定是 唯一 的。我们可以 不考虑输出结果的顺序 。
"""
from typing import List
class Solution:
def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
result = []
for i in nums1:
if i in nums2 and i not in result:
result.append(i)
return result
if __name__ == '__main__':
result = Solution().intersection([1, 2, 2, 1], [2, 2])
print(result)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册