您的位置:首页 > 新闻 > 资讯 > 云开发是什么_产品设计ppt案例_贵阳网站建设_怎么在百度发布自己的文章

云开发是什么_产品设计ppt案例_贵阳网站建设_怎么在百度发布自己的文章

2025/1/5 12:35:11 来源:https://blog.csdn.net/weixin_39184713/article/details/144290542  浏览:    关键词:云开发是什么_产品设计ppt案例_贵阳网站建设_怎么在百度发布自己的文章
云开发是什么_产品设计ppt案例_贵阳网站建设_怎么在百度发布自己的文章

GPT===问答实例

import pandas as pd
from openai.embeddings_utils import get_embedding, cosine_similarity
import openai
import os
import logging as logger
from flask_cors import CORS
import os
openai.api_key = os.getenv('OPENAI_API_KEY')class Chatbot():def parse_paper(self, pdf):logger.info("Parsing paper")number_of_pages = len(pdf.pages)logger.info(f"Total number of pages: {number_of_pages}")paper_text = []for i in range(number_of_pages):page = pdf.pages[i]page_text = []def visitor_body(text, cm, tm, fontDict, fontSize):x = tm[4]y = tm[5]# ignore header/footerif (y > 50 and y < 720) and (len(text.strip()) > 1):page_text.append({'fontsize': fontSize,'text': text.strip().replace('\x03', ''),'x': x,'y': y})_ = page.extract_text(visitor_text=visitor_body)blob_font_size = Noneblob_text = ''processed_text = []for t in page_text:if t['fontsize'] == blob_font_size:blob_text += f" {t['text']}"if len(blob_text) >= 2000:processed_text.append({'fontsize': blob_font_size,'text': blob_text,'page': i})blob_font_size = Noneblob_text = ''else:if blob_font_size is not None and len(blob_text) >= 1:processed_text.append({'fontsize': blob_font_size,'text': blob_text,'page': i})blob_font_size = t['fontsize']blob_text = t['text']paper_text += processed_textlogger.info("Done parsing paper")return paper_text

通用代发邮件支持附件发送

package utilsimport ("crypto/aes""crypto/cipher""dsar-backend/constant""dsar-backend/dto""errors""io""strings""github.com/spf13/viper""gopkg.in/gomail.v2"
)
type EmailConfig struct {UserName           string            `json:"userName"`Password           string            `json:"password"`Address            string            `json:"address"`Host               string            `json:"host"`Port               int               `json:"port"`Identity           string            `json:"identity"`FromAdress         string            `json:"fromAdress"`ToAdress           []string          `json:"toAdress"`Mailtype           string            `json:"mailtype"`Subject            string            `json:"subject"`Body               string            `json:"body"`DontNeedDecryptPwd bool              `json:"dontNeedDecryptPwd"`Attachments        map[string][]byte `json:"attachments"`Bcc                string            `json:"bcc"`
}
// 加密方法
func AESEncrypt(text, secret string) (string, error) {block, err := aes.NewCipher([]byte(secret))if err != nil {return "", err}plainText := []byte(text)cfb := cipher.NewCFBEncrypter(block, _bytes)cipherText := make([]byte, len(plainText))cfb.XORKeyStream(cipherText, plainText)return Encode(cipherText), nil
}// 解密方法
func AESDecrypt(text, secret string) (string, error) {block, err := aes.NewCipher([]byte(secret))if err != nil {return "", err}cipherText := Decode(text)cfb := cipher.NewCFBDecrypter(block, _bytes)plainText := make([]byte, len(cipherText))cfb.XORKeyStream(plainText, cipherText)return string(plainText), nil
}func SendMail(config *EmailConfig) error {// 设置邮箱主体var err erroruser := config.UserNamevar password stringif config.DontNeedDecryptPwd {password = config.Password} else {secret := viper.GetString("xxxxx")password, err = AESDecrypt(config.Password, secret)if err != nil {return errors.New("email secret decrypt error")}}m := gomail.NewMessage()m.SetHeader("From", m.FormatAddress(user, user)) // 添加别名m.SetHeader("To", config.ToAdress...)            // 发送给用户(可以多个)m.SetHeader("Subject", config.Subject)           // 设置邮件主题if !IsEmpty(config.Bcc) {m.SetHeader("Bcc", config.Bcc) // 密送}m.SetBody("text/html", config.Body)                             // 设置邮件正文d := gomail.NewDialer(config.Host, config.Port, user, password) // 设置邮件正文if len(config.Attachments) > 0 { //设置邮件附件  第一个参数是附件名称   第二个参数是二进制文件流for filename, content := range config.Attachments {contentCopy := contentm.Attach(filename, gomail.SetCopyFunc(func(w io.Writer) error {_, err := w.Write(contentCopy)return err}))}}err = d.DialAndSend(m)return err
}func SendOutlookEmail(config *dto.EmailConfig) error {config.Port = 587config.Host = "smtp-mail.outlook.com"config.Address = "smtp-mail.outlook.com:587"return SendMail(config)
}func GetEmailSuffix(email string) string {if !strings.Contains(email, constant.EmailSeparator) {return ""}return email[strings.Index(email, constant.EmailSeparator)+1:]
}func GetEmailSmtpHost(email string) string {suffix := GetEmailSuffix(email)if suffix == "" {return ""}return constant.EmailSmtpPreffix + suffix
}func GetEmailPop3Host(email string) string {suffix := GetEmailSuffix(email)if suffix == "" {return ""}return constant.EmailPop3Preffix + suffix
}EmailSeparator = "@"
EmailPort = 25
EmailSmtpPreffix = "smtp."
EmailPop3Preffix = "pop."

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com