simon824 commented on code in PR #7: URL: https://github.com/apache/incubator-hugegraph-ai/pull/7#discussion_r1364781756
########## hugegraph-llm/examples/build_kg_test.py: ########## @@ -0,0 +1,72 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +import os +from src.operators.build_kg_operator import BuildKgOperator +from src.operators.llm.openai_llm import OpenAIChat + +if __name__ == "__main__": + # If you need a proxy to access OpenAI's API, please set your HTTP proxy here + os.environ["http_proxy"] = "" + os.environ["https_proxy"] = "" + api_key = "" + + default_llm = OpenAIChat( + api_key=api_key, model_name="gpt-3.5-turbo-16k", max_tokens=4000 + ) + text = ( + "Meet Sarah, a 30-year-old attorney, and her roommate, James, whom she's shared a home with since 2010. James, " + "in his professional life, works as a journalist. Additionally, Sarah is the proud owner of the website " + "www.sarahsplace.com, while James manages his own webpage, though the specific URL is not mentioned here. " + "These two individuals, Sarah and James, have not only forged a strong personal bond as roommates but have " + "also carved out their distinctive digital presence through their respective webpages, showcasing their " + "varied interests and experiences." + ) + ops = BuildKgOperator(name="1") + # build kg with only text + ops.parse_text_to_data(default_llm).disambiguate_data( + default_llm + ).commit_data_to_kg().run(text) + # build kg with text and schemas + # nodes_schemas = [ + # { Review Comment: seems don't need to comment out these code ########## hugegraph-llm/src/operators/build_kg_operator.py: ########## @@ -0,0 +1,56 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from src.operators.build_kg.commit_data_to_kg import CommitDataToKg +from src.operators.build_kg.disambiguate_data import DisambiguateData +from src.operators.build_kg.parse_text_to_data import ( + ParseTextToData, + ParseTextToDataWithSchemas, +) + + +class BuildKgOperator: + def __init__(self, name): + self.name = name + self.parse_text_to_kg = [] + + def parse_text_to_data(self, llm): + self.parse_text_to_kg.append(ParseTextToData(llm=llm)) + return self + + def parse_text_to_data_with_schemas( + self, llm, nodes_schemas, relationships_schemas + ): + self.parse_text_to_kg.append( + ParseTextToDataWithSchemas( + llm=llm, + nodes_schema=nodes_schemas, + relationships_schemas=relationships_schemas, + ) + ) + return self + + def disambiguate_data(self, llm): Review Comment: llm will be called multiple times, we can init llm in `__init__` ########## hugegraph-llm/examples/build_kg_test.py: ########## @@ -0,0 +1,72 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +import os +from src.operators.build_kg_operator import BuildKgOperator +from src.operators.llm.openai_llm import OpenAIChat + +if __name__ == "__main__": + # If you need a proxy to access OpenAI's API, please set your HTTP proxy here + os.environ["http_proxy"] = "" + os.environ["https_proxy"] = "" + api_key = "" + + default_llm = OpenAIChat( + api_key=api_key, model_name="gpt-3.5-turbo-16k", max_tokens=4000 + ) + text = ( + "Meet Sarah, a 30-year-old attorney, and her roommate, James, whom she's shared a home with since 2010. James, " + "in his professional life, works as a journalist. Additionally, Sarah is the proud owner of the website " + "www.sarahsplace.com, while James manages his own webpage, though the specific URL is not mentioned here. " + "These two individuals, Sarah and James, have not only forged a strong personal bond as roommates but have " + "also carved out their distinctive digital presence through their respective webpages, showcasing their " + "varied interests and experiences." + ) + ops = BuildKgOperator(name="1") + # build kg with only text + ops.parse_text_to_data(default_llm).disambiguate_data( + default_llm + ).commit_data_to_kg().run(text) Review Comment: I think text should be passed to `parse_text_to_data()` instead of `run()` ########## hugegraph-llm/src/operators/build_kg_operator.py: ########## @@ -0,0 +1,56 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from src.operators.build_kg.commit_data_to_kg import CommitDataToKg +from src.operators.build_kg.disambiguate_data import DisambiguateData +from src.operators.build_kg.parse_text_to_data import ( + ParseTextToData, + ParseTextToDataWithSchemas, +) + + +class BuildKgOperator: + def __init__(self, name): + self.name = name + self.parse_text_to_kg = [] + + def parse_text_to_data(self, llm): + self.parse_text_to_kg.append(ParseTextToData(llm=llm)) + return self + + def parse_text_to_data_with_schemas( + self, llm, nodes_schemas, relationships_schemas Review Comment: we can add an operator to get schemas from hugegraph in next pr. ########## hugegraph-llm/examples/build_kg_test.py: ########## @@ -0,0 +1,72 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +import os +from src.operators.build_kg_operator import BuildKgOperator +from src.operators.llm.openai_llm import OpenAIChat + +if __name__ == "__main__": + # If you need a proxy to access OpenAI's API, please set your HTTP proxy here + os.environ["http_proxy"] = "" + os.environ["https_proxy"] = "" + api_key = "" + + default_llm = OpenAIChat( + api_key=api_key, model_name="gpt-3.5-turbo-16k", max_tokens=4000 + ) + text = ( + "Meet Sarah, a 30-year-old attorney, and her roommate, James, whom she's shared a home with since 2010. James, " + "in his professional life, works as a journalist. Additionally, Sarah is the proud owner of the website " + "www.sarahsplace.com, while James manages his own webpage, though the specific URL is not mentioned here. " + "These two individuals, Sarah and James, have not only forged a strong personal bond as roommates but have " + "also carved out their distinctive digital presence through their respective webpages, showcasing their " + "varied interests and experiences." + ) + ops = BuildKgOperator(name="1") Review Comment: what is `name` used for? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
