Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
HAMNET-AI
RoleGraph
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
RoleGraph
/
demo.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
29 lines (28 loc) · 1.32 KB
main
Breadcrumbs
RoleGraph
/
demo.py
Copy path
Top
File metadata and controls
Code
Blame
29 lines (28 loc) · 1.32 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
from langchain.llms import OpenAI
os.environ["http_proxy"] = "http://127.0.0.1:7890"
os.environ["https_proxy"] = "http://127.0.0.1:7890"
os.environ["OPENAI_API_KEY"] = "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"
import csv
def kg_generate():
llm = OpenAI(temperature=0.1)
filepath = "F:\data\hamnet//The Gift of the Magi.txt"
with open(filepath, 'r', encoding='utf-8') as file:
# 读取文件内容
text = file.read()
content = "你现在需要概括一本小说中人物的关系,定义的关系三元组有'头实体-关系-尾实体'\n要求:1、输出格式表示为头实体-关系-尾实体;2、输出的每个结果用换行符分割;3.尽可能抽取两个人物之间的关系;4.抽取7个关系\n" + f"文本:{text}"
s = llm(prompt=content)
print(s)
lines = s.split('\n')
# 创建CSV文件并写入数据
with open('relations.csv', 'w', newline='') as csvfile:
# 定义CSV表头
fieldnames = ['头实体', '关系', '尾实体']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
# 写入表头
writer.writeheader()
# 解析文本并写入CSV文件
for line in lines:
parts = line.split('-')
if len(parts) == 3:
writer.writerow({'头实体': parts[0], '关系': parts[1], '尾实体': parts[2]})
You can’t perform that action at this time.